vue.config.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. },
  16. css: [],
  17. // https://unpkg.com/browse/vue@2.6.10/
  18. js: [
  19. '//cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.min.js',
  20. '//cdn.jsdelivr.net/npm/vue-router@3.1.3/dist/vue-router.min.js',
  21. '//cdn.jsdelivr.net/npm/vuex@3.1.1/dist/vuex.min.js',
  22. '//cdn.jsdelivr.net/npm/axios@0.19.0/dist/axios.min.js'
  23. ]
  24. }
  25. // vue.config.js
  26. const vueConfig = {
  27. lintOnSave: false,
  28. configureWebpack: {
  29. // webpack plugins
  30. plugins: [
  31. // Ignore all locale files of moment.js
  32. new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)
  33. ],
  34. // if prod, add externals
  35. externals: isProd ? assetsCDN.externals : {}
  36. },
  37. chainWebpack: (config) => {
  38. config.resolve.alias
  39. .set('@$', resolve('src'))
  40. const svgRule = config.module.rule('svg')
  41. svgRule.uses.clear()
  42. svgRule
  43. .oneOf('inline')
  44. .resourceQuery(/inline/)
  45. .use('vue-svg-icon-loader')
  46. .loader('vue-svg-icon-loader')
  47. .end()
  48. .end()
  49. .oneOf('external')
  50. .use('file-loader')
  51. .loader('file-loader')
  52. .options({
  53. name: 'assets/[name].[hash:8].[ext]'
  54. })
  55. // if prod is on
  56. // assets require on cdn
  57. if (isProd) {
  58. config.plugin('html').tap(args => {
  59. args[0].cdn = assetsCDN
  60. return args
  61. })
  62. }
  63. },
  64. css: {
  65. loaderOptions: {
  66. less: {
  67. modifyVars: {
  68. 'primary-color': '#1890FF',
  69. 'layout-color': '#1890FF',
  70. 'border-radius-base': '2px'
  71. },
  72. // DO NOT REMOVE THIS LINE
  73. javascriptEnabled: true
  74. }
  75. }
  76. },
  77. devServer: {
  78. port: 8080,
  79. proxy: {
  80. '/api': {
  81. target: process.env.VUE_APP_API_BASE_URL,
  82. ws: false,
  83. changeOrigin: true,
  84. pathRewrite: {
  85. '^/api': '' // 需要rewrite的,
  86. }
  87. }
  88. }
  89. },
  90. // disable source map in production
  91. productionSourceMap: false,
  92. lintOnSave: undefined,
  93. // babel-loader no-ignore node_modules/*
  94. transpileDependencies: []
  95. }
  96. // preview.pro.loacg.com only do not use in your production;
  97. if (process.env.VUE_APP_PREVIEW === 'true') {
  98. // eslint-disable-next-line no-labels
  99. // runtimeCompiler: true,
  100. // add `ThemeColorReplacer` plugin to webpack plugins
  101. vueConfig.configureWebpack.plugins.push(createThemeColorReplacerPlugin())
  102. }
  103. module.exports = vueConfig