vue.config.js 3.7 KB

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