theme.ts 1.7 KB

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