vue.config.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. let path = require('path')
  2. const webpack = require('webpack')
  3. const ThemeColorReplacer = require('webpack-theme-color-replacer')
  4. const { getThemeColors, modifyVars } = require('./src/utils/themeUtil')
  5. const { resolveCss } = require('./src/utils/theme-color-replacer-extend')
  6. const CompressionWebpackPlugin = require('compression-webpack-plugin')
  7. const productionGzipExtensions = ['js', 'css']
  8. const isProd = process.env.NODE_ENV === 'production'
  9. const assetsCDN = {
  10. // webpack build externals
  11. externals: {
  12. vue: 'Vue',
  13. 'vue-router': 'VueRouter',
  14. vuex: 'Vuex',
  15. axios: 'axios',
  16. nprogress: 'NProgress',
  17. clipboard: 'ClipboardJS',
  18. '@antv/data-set': 'DataSet',
  19. 'js-cookie': 'Cookies'
  20. },
  21. css: [
  22. ],
  23. js: [
  24. '//cdn.jsdelivr.net/npm/vue@2.6.11/dist/vue.min.js',
  25. '//cdn.jsdelivr.net/npm/vue-router@3.6.5/dist/vue-router.min.js',
  26. '//cdn.jsdelivr.net/npm/vuex@3.4.0/dist/vuex.min.js',
  27. '//cdn.jsdelivr.net/npm/axios@0.19.2/dist/axios.min.js',
  28. '//cdn.jsdelivr.net/npm/nprogress@0.2.0/nprogress.min.js',
  29. '//cdn.jsdelivr.net/npm/clipboard@2.0.6/dist/clipboard.min.js',
  30. '//cdn.jsdelivr.net/npm/@antv/data-set@0.11.4/build/data-set.min.js',
  31. '//cdn.jsdelivr.net/npm/js-cookie@2.2.1/src/js.cookie.min.js'
  32. ]
  33. }
  34. module.exports = {
  35. devServer: {
  36. proxy: {
  37. // '/api': { //此处要与 /services/api.js 中的 API_PROXY_PREFIX 值保持一致
  38. // target: process.env.VUE_APP_API_BASE_URL,
  39. // changeOrigin: true,
  40. // pathRewrite: {
  41. // '^/api': ''
  42. // }
  43. // },
  44. "/web-api": { //设置第一代理
  45. target: 'http://39.98.239.48/web-api',
  46. secure: false,
  47. //secure:false, //如果是https接口,需要配置这个参数
  48. ws: true,
  49. changeOrigin: true, //如果接口跨域需要配置这个参数
  50. pathRewrite: {
  51. '^/web-api': '/'
  52. }
  53. }
  54. }
  55. },
  56. pluginOptions: {
  57. 'style-resources-loader': {
  58. preProcessor: 'less',
  59. patterns: [path.resolve(__dirname, "./src/theme/theme.less")],
  60. }
  61. },
  62. configureWebpack: config => {
  63. config.entry.app = ["babel-polyfill", "whatwg-fetch", "./src/main.js"];
  64. config.performance = {
  65. hints: false
  66. }
  67. config.plugins.push(
  68. new ThemeColorReplacer({
  69. fileName: 'css/theme-colors-[contenthash:8].css',
  70. matchColors: getThemeColors(),
  71. injectCss: true,
  72. resolveCss
  73. })
  74. )
  75. // Ignore all locale files of moment.js
  76. config.plugins.push(new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/))
  77. // 生产环境下将资源压缩成gzip格式
  78. if (isProd) {
  79. // add `CompressionWebpack` plugin to webpack plugins
  80. config.plugins.push(new CompressionWebpackPlugin({
  81. algorithm: 'gzip',
  82. test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
  83. threshold: 10240,
  84. minRatio: 0.8
  85. }))
  86. }
  87. // if prod, add externals
  88. if (isProd) {
  89. config.externals = assetsCDN.externals
  90. }
  91. },
  92. chainWebpack: config => {
  93. // 生产环境下关闭css压缩的 colormin 项,因为此项优化与主题色替换功能冲突
  94. if (isProd) {
  95. config.plugin('optimize-css')
  96. .tap(args => {
  97. args[0].cssnanoOptions.preset[1].colormin = false
  98. return args
  99. })
  100. }
  101. // 生产环境下使用CDN
  102. if (isProd) {
  103. config.plugin('html')
  104. .tap(args => {
  105. args[0].cdn = assetsCDN
  106. return args
  107. })
  108. }
  109. },
  110. css: {
  111. loaderOptions: {
  112. less: {
  113. lessOptions: {
  114. modifyVars: modifyVars(),
  115. javascriptEnabled: true
  116. }
  117. }
  118. }
  119. },
  120. // publicPath: 'https://sxzgkj.baoxianzhanggui.com/console-api',
  121. publicPath: '/',
  122. outputDir: 'dist',
  123. assetsDir: 'static',
  124. productionSourceMap: false
  125. }