Vben
2021-04-07 5b8eb4a49a097a47caf491c44df427522ab58daa
提交 | 用户 | age
07c18d 1 /**
V 2  * Vite plugin for website theme color switching
3  * https://github.com/anncwb/vite-plugin-theme
4  */
5b8eb4 5 import type { Plugin } from 'vite';
V 6 import {
7   viteThemePlugin,
8   antdDarkThemePlugin,
9   mixLighten,
10   mixDarken,
11   tinycolor,
12 } from 'vite-plugin-theme';
3d1681 13 import { getThemeColors, generateColors } from '../../config/themeConfig';
5b8eb4 14 import { generateModifyVars } from '../../generate/generateModifyVars';
3d1681 15
5b8eb4 16 export function configThemePlugin(isBuild: boolean): Plugin[] {
3d1681 17   const colors = generateColors({
V 18     mixDarken,
19     mixLighten,
20     tinycolor,
21   });
22
5b8eb4 23   const plugin = [
V 24     viteThemePlugin({
25       resolveSelector: (s) => `[data-theme] ${s}`,
26       colorVariables: [...getThemeColors(), ...colors],
27     }),
28     antdDarkThemePlugin({
29       filter: (id) => {
30         if (isBuild) {
31           return !id.endsWith('antd.less');
32         }
33         return true;
34       },
35       // extractCss: false,
36       darkModifyVars: {
37         ...generateModifyVars(true),
38         'text-color': '#c9d1d9',
39         'text-color-base': '#c9d1d9',
40         'component-background': '#151515',
41         // black: '#0e1117',
42         // #8b949e
43         'text-color-secondary': '#8b949e',
44         'border-color-base': '#30363d',
45         'item-active-bg': '#111b26',
46       },
47     }),
48   ];
49
50   return (plugin as unknown) as Plugin[];
3d1681 51 }