vben-admin-thin-next/build/vite/plugin/theme.ts

63 lines
1.8 KiB
TypeScript
Raw Normal View History

2021-02-09 23:47:14 +08:00
/**
* Vite plugin for website theme color switching
* https://github.com/anncwb/vite-plugin-theme
*/
2021-04-07 23:14:51 +08:00
import type { Plugin } from 'vite';
2021-04-08 22:08:55 +08:00
import path from 'path';
2021-04-07 23:14:51 +08:00
import {
viteThemePlugin,
antdDarkThemePlugin,
mixLighten,
mixDarken,
tinycolor,
} from 'vite-plugin-theme';
2021-02-03 23:52:55 +08:00
import { getThemeColors, generateColors } from '../../config/themeConfig';
2021-04-07 23:14:51 +08:00
import { generateModifyVars } from '../../generate/generateModifyVars';
2021-02-03 23:52:55 +08:00
2021-04-07 23:14:51 +08:00
export function configThemePlugin(isBuild: boolean): Plugin[] {
2021-02-03 23:52:55 +08:00
const colors = generateColors({
mixDarken,
mixLighten,
tinycolor,
});
2021-04-07 23:14:51 +08:00
const plugin = [
viteThemePlugin({
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';
case '.ant-steps-item-icon > .ant-steps-icon':
return s;
}
return `[data-theme] ${s}`;
},
2021-04-07 23:14:51 +08:00
colorVariables: [...getThemeColors(), ...colors],
}),
antdDarkThemePlugin({
2021-04-08 22:08:55 +08:00
preloadFiles: [
path.resolve(process.cwd(), 'node_modules/ant-design-vue/dist/antd.less'),
path.resolve(process.cwd(), 'src/design/index.less'),
],
2021-04-08 22:08:12 +08:00
filter: (id) => (isBuild ? !id.endsWith('antd.less') : true),
2021-04-07 23:14:51 +08:00
// extractCss: false,
darkModifyVars: {
...generateModifyVars(true),
'text-color': '#c9d1d9',
'text-color-base': '#c9d1d9',
'component-background': '#151515',
// black: '#0e1117',
// #8b949e
'text-color-secondary': '#8b949e',
2021-04-10 21:18:35 +08:00
'border-color-base': '#303030',
// 'border-color-split': '#30363d',
2021-04-07 23:14:51 +08:00
'item-active-bg': '#111b26',
2021-04-17 18:36:49 +08:00
'content-background': '#ffffff0a', // Link color
2021-04-07 23:14:51 +08:00
},
}),
];
return (plugin as unknown) as Plugin[];
2021-02-03 23:52:55 +08:00
}