vue.config.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. const path = require('path')
  2. const webpack = require('webpack')
  3. const createThemeColorReplacerPlugin = require('./config/plugin.config')
  4. function resolve (dir) {
  5. return path.join(__dirname, dir)
  6. }
  7. const isProd = process.env.NODE_ENV === 'production'
  8. const assetsCDN = {
  9. // webpack build externals
  10. externals: {
  11. vue: 'Vue',
  12. 'vue-router': 'VueRouter',
  13. vuex: 'Vuex',
  14. axios: 'axios',
  15. 'ant-design-vue': 'antd',
  16. 'moment': 'moment'
  17. },
  18. css: [],
  19. // https://unpkg.com/browse/vue@2.6.10/
  20. js: [
  21. '//cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.min.js',
  22. '//cdn.jsdelivr.net/npm/vue-router@3.1.3/dist/vue-router.min.js',
  23. '//cdn.jsdelivr.net/npm/vuex@3.1.1/dist/vuex.min.js',
  24. '//cdn.jsdelivr.net/npm/axios@0.19.0/dist/axios.min.js',
  25. 'https://cdn.jsdelivr.net/npm/moment@2.24.0/min/moment.min.js',
  26. 'https://cdn.jsdelivr.net/npm/ant-design-vue@1.4.12/dist/antd.min.js'
  27. ]
  28. }
  29. // vue.config.js
  30. const vueConfig = {
  31. configureWebpack: {
  32. // webpack plugins
  33. plugins: [
  34. // Ignore all locale files of moment.js
  35. new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)
  36. ],
  37. // if prod, add externals
  38. externals: isProd ? assetsCDN.externals : {}
  39. },
  40. chainWebpack: (config) => {
  41. config.resolve.alias
  42. .set('@$', resolve('src'))
  43. const svgRule = config.module.rule('svg')
  44. svgRule.uses.clear()
  45. svgRule
  46. .oneOf('inline')
  47. .resourceQuery(/inline/)
  48. .use('vue-svg-icon-loader')
  49. .loader('vue-svg-icon-loader')
  50. .end()
  51. .end()
  52. .oneOf('external')
  53. .use('file-loader')
  54. .loader('file-loader')
  55. .options({
  56. name: 'assets/[name].[hash:8].[ext]'
  57. })
  58. // if prod is on
  59. // assets require on cdn
  60. if (isProd) {
  61. config.plugin('html').tap(args => {
  62. args[0].cdn = assetsCDN
  63. return args
  64. })
  65. }
  66. },
  67. css: {
  68. loaderOptions: {
  69. less: {
  70. modifyVars: {
  71. // less vars,customize ant design theme
  72. // 'primary-color': '#F5222D',
  73. // 'link-color': '#F5222D',
  74. // 'border-radius-base': '4px'
  75. },
  76. // DO NOT REMOVE THIS LINE
  77. javascriptEnabled: true
  78. }
  79. }
  80. },
  81. devServer: {
  82. // development server port 8000
  83. port: 8000
  84. // If you want to turn on the proxy, please remove the mockjs /src/main.jsL11
  85. // proxy: {
  86. // '/api': {
  87. // target: 'https://mock.ihx.me/mock/5baf3052f7da7e07e04a5116/antd-pro',
  88. // ws: false,
  89. // changeOrigin: true
  90. // }
  91. // }
  92. },
  93. // disable source map in production
  94. productionSourceMap: false,
  95. lintOnSave: undefined,
  96. // babel-loader no-ignore node_modules/*
  97. transpileDependencies: []
  98. }
  99. // preview.pro.loacg.com only do not use in your production;
  100. if (process.env.VUE_APP_PREVIEW === 'true') {
  101. console.log('VUE_APP_PREVIEW', true)
  102. // add `ThemeColorReplacer` plugin to webpack plugins
  103. vueConfig.configureWebpack.plugins.push(createThemeColorReplacerPlugin())
  104. }
  105. module.exports = vueConfig