vben
authored
4 years ago
1
2
3
4
/**
* Vite plugin for website theme color switching
* https://github.com/anncwb/vite-plugin-theme
*/
Vben
authored
4 years ago
5
import type { Plugin } from 'vite';
Vben
authored
4 years ago
6
import path from 'path';
Vben
authored
4 years ago
7
8
9
10
11
12
13
import {
viteThemePlugin,
antdDarkThemePlugin,
mixLighten,
mixDarken,
tinycolor,
} from 'vite-plugin-theme';
vben
authored
4 years ago
14
import { getThemeColors, generateColors } from '../../config/themeConfig';
Vben
authored
4 years ago
15
import { generateModifyVars } from '../../generate/generateModifyVars';
vben
authored
4 years ago
16
Vben
authored
4 years ago
17
export function configThemePlugin(isBuild: boolean): Plugin[] {
vben
authored
4 years ago
18
19
20
21
22
const colors = generateColors({
mixDarken,
mixLighten,
tinycolor,
});
Vben
authored
4 years ago
23
24
const plugin = [
viteThemePlugin({
Vben
authored
4 years ago
25
26
27
28
29
resolveSelector: (s) => {
s = s.trim();
switch (s) {
case '.ant-steps-item-process .ant-steps-item-icon > .ant-steps-icon':
return '.ant-steps-item-icon > .ant-steps-icon';
30
31
32
33
case '.ant-radio-button-wrapper-checked:not(.ant-radio-button-wrapper-disabled)':
case '.ant-radio-button-wrapper-checked:not(.ant-radio-button-wrapper-disabled):hover':
case '.ant-radio-button-wrapper-checked:not(.ant-radio-button-wrapper-disabled):active':
return s;
Vben
authored
4 years ago
34
35
36
37
38
case '.ant-steps-item-icon > .ant-steps-icon':
return s;
}
return `[data-theme] ${s}`;
},
Vben
authored
4 years ago
39
40
41
colorVariables: [...getThemeColors(), ...colors],
}),
antdDarkThemePlugin({
Vben
authored
4 years ago
42
43
44
45
preloadFiles: [
path.resolve(process.cwd(), 'node_modules/ant-design-vue/dist/antd.less'),
path.resolve(process.cwd(), 'src/design/index.less'),
],
Vben
authored
4 years ago
46
filter: (id) => (isBuild ? !id.endsWith('antd.less') : true),
Vben
authored
4 years ago
47
48
49
50
51
52
53
54
55
// extractCss: false,
darkModifyVars: {
...generateModifyVars(true),
'text-color': '#c9d1d9',
'text-color-base': '#c9d1d9',
'component-background': '#151515',
// black: '#0e1117',
// #8b949e
'text-color-secondary': '#8b949e',
Vben
authored
4 years ago
56
'border-color-base': '#303030',
Vben
authored
4 years ago
57
// 'border-color-split': '#30363d',
Vben
authored
4 years ago
58
'item-active-bg': '#111b26',
Vben
authored
4 years ago
59
'app-content-background': 'rgb(255 255 255 / 4%)',
Vben
authored
4 years ago
60
61
62
63
},
}),
];
64
return plugin as unknown as Plugin[];
vben
authored
4 years ago
65
}