vue.config.js 2.6 KB

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