vue.config.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. // check Git
  11. function getGitHash () {
  12. try {
  13. return GitRevision.version()
  14. } catch (e) {}
  15. return 'unknown'
  16. }
  17. // eslint-disable-next-line no-unused-vars
  18. const isProd = process.env.NODE_ENV === 'production'
  19. // eslint-disable-next-line no-unused-vars
  20. const assetsCDN = {
  21. // webpack build externals
  22. externals: {
  23. vue: 'Vue',
  24. 'vue-router': 'VueRouter',
  25. vuex: 'Vuex',
  26. axios: 'axios'
  27. },
  28. css: [],
  29. // https://unpkg.com/browse/vue@2.6.10/
  30. js: [
  31. '//cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.min.js',
  32. '//cdn.jsdelivr.net/npm/vue-router@3.5.1/dist/vue-router.min.js',
  33. '//cdn.jsdelivr.net/npm/vuex@3.1.1/dist/vuex.min.js',
  34. '//cdn.jsdelivr.net/npm/axios@0.21.1/dist/axios.min.js'
  35. ]
  36. }
  37. // vue.config.js
  38. const vueConfig = {
  39. configureWebpack: {
  40. // webpack plugins
  41. plugins: [
  42. // Ignore all locale files of moment.js
  43. new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
  44. new webpack.DefinePlugin({
  45. APP_VERSION: `"${require('./package.json').version}"`,
  46. GIT_HASH: JSON.stringify(getGitHash()),
  47. BUILD_DATE: buildDate
  48. })
  49. ]
  50. // en_US: `if prod, add externals`
  51. // zh_CN: `这里是用来控制编译忽略外部依赖的,与 config.plugin('html') 配合可以编译时引入外部CDN文件依赖`
  52. // externals: isProd ? assetsCDN.externals : {}
  53. },
  54. chainWebpack: config => {
  55. config.resolve.alias.set('@$', resolve('src'))
  56. const svgRule = config.module.rule('svg')
  57. svgRule.uses.clear()
  58. svgRule
  59. .oneOf('inline')
  60. .resourceQuery(/inline/)
  61. .use('vue-svg-icon-loader')
  62. .loader('vue-svg-icon-loader')
  63. .end()
  64. .end()
  65. .oneOf('external')
  66. .use('file-loader')
  67. .loader('file-loader')
  68. .options({
  69. name: 'assets/[name].[hash:8].[ext]',
  70. esModule: false
  71. })
  72. // en_US: If prod is on assets require on cdn
  73. // zh_CN: 如果是 prod 模式,则引入 CDN 依赖文件,有需要减少包大小请自行解除依赖
  74. //
  75. // if (isProd) {
  76. // config.plugin('html').tap(args => {
  77. // args[0].cdn = assetsCDN
  78. // return args
  79. // })
  80. // }
  81. },
  82. css: {
  83. loaderOptions: {
  84. less: {
  85. modifyVars: {
  86. // less vars,customize ant design theme
  87. // 'primary-color': '#F5222D',
  88. // 'link-color': '#F5222D',
  89. 'border-radius-base': '2px'
  90. },
  91. // DO NOT REMOVE THIS LINE
  92. javascriptEnabled: true
  93. }
  94. }
  95. },
  96. devServer: {
  97. // development server port 8000
  98. port: 8000
  99. // If you want to turn on the proxy, please remove the mockjs /src/main.jsL11
  100. // proxy: {
  101. // '/api': {
  102. // target: 'https://mock.ihx.me/mock/5baf3052f7da7e07e04a5116/antd-pro',
  103. // ws: false,
  104. // changeOrigin: true
  105. // }
  106. // }
  107. },
  108. // disable source map in production
  109. productionSourceMap: false,
  110. lintOnSave: undefined,
  111. // babel-loader no-ignore node_modules/*
  112. transpileDependencies: []
  113. }
  114. // preview.pro.loacg.com only do not use in your production;
  115. if (process.env.VUE_APP_PREVIEW === 'true') {
  116. // add `ThemeColorReplacer` plugin to webpack plugins
  117. vueConfig.configureWebpack.plugins.push(createThemeColorReplacerPlugin())
  118. }
  119. module.exports = vueConfig