vue.config.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. // less vars,customize ant design theme
  68. // 'primary-color': '#F5222D',
  69. // 'link-color': '#F5222D',
  70. // 'border-radius-base': '4px'
  71. },
  72. // DO NOT REMOVE THIS LINE
  73. javascriptEnabled: true
  74. }
  75. }
  76. },
  77. devServer: {
  78. // development server port 8000
  79. port: 8000,
  80. proxy: {
  81. // change xxx-api/login => mock/login
  82. // detail: https://cli.vuejs.org/config/#devserver-proxy
  83. [process.env.VUE_APP_API_BASE_URL]: {
  84. target: `http://127.0.0.1:8087/deliver`,
  85. changeOrigin: true,
  86. pathRewrite: { '^/deliver': '/' }
  87. }
  88. }
  89. // If you want to turn on the proxy, please remove the mockjs /src/main.jsL11
  90. // proxy: {
  91. // '/api': {
  92. // target: 'https://mock.ihx.me/mock/5baf3052f7da7e07e04a5116/antd-pro',
  93. // ws: false,
  94. // changeOrigin: true
  95. // }
  96. // }
  97. },
  98. // disable source map in production
  99. productionSourceMap: false,
  100. lintOnSave: false,
  101. publicPath: '/admin',
  102. outputDir: 'dist',
  103. assetsDir: 'static',
  104. // babel-loader no-ignore node_modules/*
  105. transpileDependencies: []
  106. }
  107. // preview.pro.loacg.com only do not use in your production;
  108. if (process.env.VUE_APP_PREVIEW === 'true') {
  109. console.log('VUE_APP_PREVIEW', true)
  110. // add `ThemeColorReplacer` plugin to webpack plugins
  111. vueConfig.configureWebpack.plugins.push(createThemeColorReplacerPlugin())
  112. }
  113. module.exports = vueConfig