vue.config.js 2.8 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. },
  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. outputDir:"zjxlBackstage",
  28. publicPath: process.env.assetsPublicPath,
  29. assetsDir: 'static',
  30. lintOnSave: false,
  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. 'primary-color': '#1890FF',
  72. 'layout-color': '#1890FF',
  73. 'border-radius-base': '2px'
  74. },
  75. // DO NOT REMOVE THIS LINE
  76. javascriptEnabled: true
  77. }
  78. }
  79. },
  80. // devServer: {
  81. // port: 8080,
  82. // proxy: {
  83. // '/api': {
  84. // target: process.env.VUE_APP_API_BASE_URL,
  85. // ws: false,
  86. // changeOrigin: true,
  87. // pathRewrite: {
  88. // '^/api': '' // 需要rewrite的,
  89. // }
  90. // }
  91. // }
  92. // },
  93. // disable source map in production
  94. productionSourceMap: false,
  95. // babel-loader no-ignore node_modules/*
  96. transpileDependencies: []
  97. }
  98. // preview.pro.loacg.com only do not use in your production;
  99. if (process.env.VUE_APP_PREVIEW === 'true') {
  100. // eslint-disable-next-line no-labels
  101. // runtimeCompiler: true,
  102. // add `ThemeColorReplacer` plugin to webpack plugins
  103. vueConfig.configureWebpack.plugins.push(createThemeColorReplacerPlugin())
  104. }
  105. module.exports = vueConfig