vue.config.js 2.9 KB

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