vue.config.js 3.3 KB

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