vue.config.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. const path = require('path')
  2. const webpack = require('webpack')
  3. const ThemeColorReplacer = require('webpack-theme-color-replacer')
  4. const generate = require('@ant-design/colors/lib/generate').default
  5. function resolve (dir) {
  6. return path.join(__dirname, dir)
  7. }
  8. // vue.config.js
  9. module.exports = {
  10. /*
  11. Vue-cli3:
  12. Crashed when using Webpack `import()` #2463
  13. https://github.com/vuejs/vue-cli/issues/2463
  14. */
  15. /*
  16. pages: {
  17. index: {
  18. entry: 'src/main.js',
  19. chunks: ['chunk-vendors', 'chunk-common', 'index']
  20. }
  21. },
  22. */
  23. configureWebpack: {
  24. plugins: [
  25. // Ignore all locale files of moment.js
  26. new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
  27. // 生成仅包含颜色的替换样式(主题色等)
  28. new ThemeColorReplacer({
  29. fileName: 'css/theme-colors.css',
  30. matchColors: getAntdSerials('#1890ff'), // 主色系列
  31. // 改变样式选择器,解决样式覆盖问题
  32. changeSelector (selector) {
  33. switch (selector) {
  34. case '.ant-calendar-today .ant-calendar-date':
  35. return ':not(.ant-calendar-selected-date)' + selector
  36. case '.ant-btn:focus,.ant-btn:hover':
  37. return '.ant-btn:focus:not(.ant-btn-primary),.ant-btn:hover:not(.ant-btn-primary)'
  38. case '.ant-btn.active,.ant-btn:active':
  39. return '.ant-btn.active:not(.ant-btn-primary),.ant-btn:active:not(.ant-btn-primary)'
  40. default :
  41. return selector
  42. }
  43. }
  44. })
  45. ]
  46. },
  47. chainWebpack: (config) => {
  48. config.resolve.alias
  49. .set('@$', resolve('src'))
  50. const svgRule = config.module.rule('svg')
  51. svgRule.uses.clear()
  52. svgRule
  53. .oneOf('inline')
  54. .resourceQuery(/inline/)
  55. .use('vue-svg-icon-loader')
  56. .loader('vue-svg-icon-loader')
  57. .end()
  58. .end()
  59. .oneOf('external')
  60. .use('file-loader')
  61. .loader('file-loader')
  62. .options({
  63. name: 'assets/[name].[hash:8].[ext]'
  64. })
  65. /* svgRule.oneOf('inline')
  66. .resourceQuery(/inline/)
  67. .use('vue-svg-loader')
  68. .loader('vue-svg-loader')
  69. .end()
  70. .end()
  71. .oneOf('external')
  72. .use('file-loader')
  73. .loader('file-loader')
  74. .options({
  75. name: 'assets/[name].[hash:8].[ext]'
  76. })
  77. */
  78. },
  79. css: {
  80. loaderOptions: {
  81. less: {
  82. modifyVars: {
  83. /* less 变量覆盖,用于自定义 ant design 主题 */
  84. /*
  85. 'primary-color': '#F5222D',
  86. 'link-color': '#F5222D',
  87. 'border-radius-base': '4px',
  88. */
  89. },
  90. javascriptEnabled: true
  91. }
  92. }
  93. },
  94. devServer: {
  95. // development server port 8000
  96. port: 8000
  97. // proxy: {
  98. // '/api': {
  99. // // target: 'https://mock.ihx.me/mock/5baf3052f7da7e07e04a5116/antd-pro',
  100. // target: 'https://mock.ihx.me/mock/5baf3052f7da7e07e04a5116/antd-pro',
  101. // ws: false,
  102. // changeOrigin: true
  103. // }
  104. // }
  105. },
  106. // disable source map in production
  107. productionSourceMap: false,
  108. lintOnSave: undefined,
  109. // babel-loader no-ignore node_modules/*
  110. transpileDependencies: []
  111. }
  112. function getAntdSerials (color) {
  113. // 淡化(即less的tint)
  114. const lightens = new Array(9).fill().map((t, i) => {
  115. return ThemeColorReplacer.varyColor.lighten(color, i / 10)
  116. })
  117. const colorPalettes = generate(color)
  118. return lightens.concat(colorPalettes)
  119. }