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

52 lines
1.3 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';
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) => `[data-theme] ${s}`,
colorVariables: [...getThemeColors(), ...colors],
}),
antdDarkThemePlugin({
filter: (id) => {
if (isBuild) {
return !id.endsWith('antd.less');
}
return true;
},
// extractCss: false,
darkModifyVars: {
...generateModifyVars(true),
'text-color': '#c9d1d9',
'text-color-base': '#c9d1d9',
'component-background': '#151515',
// black: '#0e1117',
// #8b949e
'text-color-secondary': '#8b949e',
'border-color-base': '#30363d',
'item-active-bg': '#111b26',
},
}),
];
return (plugin as unknown) as Plugin[];
2021-02-03 23:52:55 +08:00
}