plugin.config.js 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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) 替换`24,144,255`这样的主题色
  10. const rgb = ThemeColorReplacer.varyColor.toNum3(color.replace('#', '')).join(',')
  11. return lightens.concat(colorPalettes).concat(rgb)
  12. }
  13. const themePluginOption = {
  14. fileName: 'css/theme-colors-[contenthash:8].css',
  15. matchColors: getAntdSerials('#1890ff'), // 主色系列
  16. // 改变样式选择器,解决样式覆盖问题
  17. changeSelector (selector) {
  18. switch (selector) {
  19. case '.ant-calendar-today .ant-calendar-date':
  20. return ':not(.ant-calendar-selected-date):not(.ant-calendar-selected-day)' + selector
  21. case '.ant-btn:focus,.ant-btn:hover':
  22. return '.ant-btn:focus:not(.ant-btn-primary):not(.ant-btn-danger),.ant-btn:hover:not(.ant-btn-primary):not(.ant-btn-danger)'
  23. case '.ant-btn.active,.ant-btn:active':
  24. return '.ant-btn.active:not(.ant-btn-primary):not(.ant-btn-danger),.ant-btn:active:not(.ant-btn-primary):not(.ant-btn-danger)'
  25. case '.ant-steps-item-process .ant-steps-item-icon > .ant-steps-icon':
  26. return ':not(.ant-steps-item-process)' + selector
  27. 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':
  28. 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':
  29. 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'
  30. case '.ant-menu-horizontal > .ant-menu-item-selected > a':
  31. return '.ant-menu-horizontal:not(ant-menu-light):not(.ant-menu-dark) > .ant-menu-item-selected > a'
  32. case '.ant-menu-horizontal > .ant-menu-item > a:hover':
  33. return '.ant-menu-horizontal:not(ant-menu-light):not(.ant-menu-dark) > .ant-menu-item > a:hover'
  34. default :
  35. return selector
  36. }
  37. }
  38. }
  39. const createThemeColorReplacerPlugin = () => new ThemeColorReplacer(themePluginOption)
  40. module.exports = createThemeColorReplacerPlugin