vue.config.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. '//lib.baomitu.com/vue/2.6.10/vue.min.js',
  23. '//lib.baomitu.com/vue-router/3.1.3/vue-router.min.js',
  24. '//lib.baomitu.com/vuex/3.1.1/vuex.min.js',
  25. '//lib.baomitu.com/axios/0.19.0/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. // 默认蓝
  81. // 'primary-color': '#1890ff',
  82. // 'link-color': '#1890ff',
  83. 'font-size-base': '13px',
  84. 'border-radius-base': '2px'
  85. },
  86. // DO NOT REMOVE THIS LINE
  87. javascriptEnabled: true
  88. }
  89. }
  90. },
  91. devServer: {
  92. // development server port 8000
  93. port: 8000
  94. // If you want to turn on the proxy, please remove the mockjs /src/main.jsL11
  95. // proxy: {
  96. // '/api': {
  97. // target: 'https:/www.abc.com/index.php/store',
  98. // ws: false,
  99. // changeOrigin: true,
  100. // pathRewrite: {
  101. // '/api': ''
  102. // }
  103. // }
  104. // }
  105. },
  106. // disable source map in production
  107. productionSourceMap: false,
  108. lintOnSave: false,
  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. console.log('VUE_APP_PREVIEW', true)
  115. // add `ThemeColorReplacer` plugin to webpack plugins
  116. vueConfig.configureWebpack.plugins.push(createThemeColorReplacerPlugin())
  117. }
  118. module.exports = vueConfig