vue.config.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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(/^\.\/locale$/, /moment$/),
  44. new BundleAnalyzerPlugin()
  45. // new webpack.DefinePlugin({
  46. // APP_VERSION: `"${require('./package.json').version}"`,
  47. // GIT_HASH: JSON.stringify(GitRevision.version()),
  48. // BUILD_DATE: buildDate
  49. // })
  50. ],
  51. // if prod, add externals
  52. externals: isProd ? assetsCDN.externals : {}
  53. },
  54. chainWebpack: (config) => {
  55. config.resolve.alias
  56. .set('@$', resolve('src'))
  57. const svgRule = config.module.rule('svg')
  58. svgRule.uses.clear()
  59. svgRule
  60. .oneOf('inline')
  61. .resourceQuery(/inline/)
  62. .use('vue-svg-icon-loader')
  63. .loader('vue-svg-icon-loader')
  64. .end()
  65. .end()
  66. .oneOf('external')
  67. .use('file-loader')
  68. .loader('file-loader')
  69. .options({
  70. name: 'assets/[name].[hash:8].[ext]'
  71. })
  72. // if prod is on
  73. // assets require on cdn
  74. if (isProd) {
  75. config.plugin('html').tap(args => {
  76. args[0].cdn = assetsCDN
  77. return args
  78. })
  79. }
  80. },
  81. css: {
  82. // 定位css文件
  83. sourceMap: true,
  84. loaderOptions: {
  85. less: {
  86. modifyVars: {
  87. // less vars,customize ant design theme
  88. // 'primary-color': '#F5222D',
  89. // 'link-color': '#F5222D',
  90. 'border-radius-base': '2px'
  91. },
  92. // DO NOT REMOVE THIS LINE
  93. javascriptEnabled: true
  94. }
  95. }
  96. },
  97. devServer: {
  98. // development server port 8000
  99. port: 8000
  100. // If you want to turn on the proxy, please remove the mockjs /src/main.jsL11
  101. // proxy: {
  102. // '/api': {
  103. // target: 'https:/www.abc.com/index.php/store',
  104. // ws: false,
  105. // changeOrigin: true,
  106. // pathRewrite: {
  107. // '/api': ''
  108. // }
  109. // }
  110. // }
  111. },
  112. // disable source map in production
  113. productionSourceMap: false,
  114. lintOnSave: false,
  115. // babel-loader no-ignore node_modules/*
  116. transpileDependencies: []
  117. }
  118. // preview.pro.loacg.com only do not use in your production;
  119. if (process.env.VUE_APP_PREVIEW === 'true') {
  120. console.log('VUE_APP_PREVIEW', true)
  121. // add `ThemeColorReplacer` plugin to webpack plugins
  122. vueConfig.configureWebpack.plugins.push(createThemeColorReplacerPlugin())
  123. }
  124. module.exports = vueConfig