vue.config.js 2.9 KB

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