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