vue.config.js 3.1 KB

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