plugin.config.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. const ThemeColorReplacer = require('webpack-theme-color-replacer')
  2. const generate = require('@ant-design/colors/lib/generate').default
  3. const getAntdSerials = (color) => {
  4. // 淡化(即less的tint)
  5. const lightens = new Array(9).fill().map((t, i) => {
  6. return ThemeColorReplacer.varyColor.lighten(color, i / 10)
  7. })
  8. const colorPalettes = generate(color)
  9. return lightens.concat(colorPalettes)
  10. }
  11. const themePluginOption = {
  12. fileName: 'css/theme-colors-[contenthash:8].css',
  13. matchColors: getAntdSerials('#1890ff'), // 主色系列
  14. // 改变样式选择器,解决样式覆盖问题
  15. changeSelector (selector) {
  16. switch (selector) {
  17. case '.ant-calendar-today .ant-calendar-date':
  18. return ':not(.ant-calendar-selected-date):not(.ant-calendar-selected-day)' + selector
  19. case '.ant-btn:focus,.ant-btn:hover':
  20. return '.ant-btn:focus:not(.ant-btn-primary):not(.ant-btn-danger),.ant-btn:hover:not(.ant-btn-primary):not(.ant-btn-danger)'
  21. case '.ant-btn.active,.ant-btn:active':
  22. return '.ant-btn.active:not(.ant-btn-primary):not(.ant-btn-danger),.ant-btn:active:not(.ant-btn-primary):not(.ant-btn-danger)'
  23. case '.ant-steps-item-process .ant-steps-item-icon > .ant-steps-icon':
  24. return ':not(.ant-steps-item-process)' + selector
  25. case '.ant-menu-horizontal>.ant-menu-item-active,.ant-menu-horizontal>.ant-menu-item-open,.ant-menu-horizontal>.ant-menu-item-selected,.ant-menu-horizontal>.ant-menu-item:hover,.ant-menu-horizontal>.ant-menu-submenu-active,.ant-menu-horizontal>.ant-menu-submenu-open,.ant-menu-horizontal>.ant-menu-submenu-selected,.ant-menu-horizontal>.ant-menu-submenu:hover':
  26. case '.ant-menu-horizontal > .ant-menu-item-active,.ant-menu-horizontal > .ant-menu-item-open,.ant-menu-horizontal > .ant-menu-item-selected,.ant-menu-horizontal > .ant-menu-item:hover,.ant-menu-horizontal > .ant-menu-submenu-active,.ant-menu-horizontal > .ant-menu-submenu-open,.ant-menu-horizontal > .ant-menu-submenu-selected,.ant-menu-horizontal > .ant-menu-submenu:hover':
  27. return '.ant-menu-horizontal > .ant-menu-item-active,.ant-menu-horizontal > .ant-menu-item-open,.ant-menu-horizontal > .ant-menu-item-selected,.ant-menu-horizontal:not(.ant-menu-dark) > .ant-menu-item:hover,.ant-menu-horizontal > .ant-menu-submenu-active,.ant-menu-horizontal > .ant-menu-submenu-open,.ant-menu-horizontal:not(.ant-menu-dark) > .ant-menu-submenu-selected,.ant-menu-horizontal:not(.ant-menu-dark) > .ant-menu-submenu:hover'
  28. case '.ant-menu-horizontal > .ant-menu-item-selected > a':
  29. return '.ant-menu-horizontal:not(ant-menu-light):not(.ant-menu-dark) > .ant-menu-item-selected > a'
  30. case '.ant-menu-horizontal > .ant-menu-item > a:hover':
  31. return '.ant-menu-horizontal:not(ant-menu-light):not(.ant-menu-dark) > .ant-menu-item > a:hover'
  32. default :
  33. return selector
  34. }
  35. }
  36. }
  37. const createThemeColorReplacerPlugin = () => new ThemeColorReplacer(themePluginOption)
  38. module.exports = createThemeColorReplacerPlugin