vue.config.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. const { defineConfig } = require('@vue/cli-service')
  2. // 解决 MaxListenersExceededWarning 警告
  3. require('events').EventEmitter.defaultMaxListeners = 20;
  4. // 解决 util._extend 已弃用警告
  5. const util = require('util');
  6. // 直接覆盖而不是条件检查,确保修复生效
  7. util._extend = Object.assign;
  8. const path = require('path')
  9. const webpack = require('webpack')
  10. const CompressionWebpackPlugin = require("compression-webpack-plugin");
  11. function resolve(dir) {
  12. return path.join(__dirname, dir)
  13. }
  14. module.exports = defineConfig({
  15. transpileDependencies: true,
  16. publicPath: "/kdyjs/",
  17. pages: {
  18. index: {
  19. // page 的入口
  20. entry: 'src/main.js',
  21. // 模板来源
  22. template: 'public/index.html',
  23. // 在 dist/index.html 的输出
  24. filename: 'index.html',
  25. // 当使用 title 选项时,
  26. // template 中的 title 标签需要是 <title><%= htmlWebpackPlugin.options.title %></title>
  27. title: '开店一件事',
  28. // 在这个页面中包含的块,默认情况下会包含
  29. // 提取出来的通用 chunk 和 vendor chunk。
  30. chunks: ['chunk-vendors', 'chunk-common', 'index']
  31. }
  32. },
  33. // ...other config
  34. configureWebpack: config => {
  35. config.performance = {
  36. hints: 'warning',
  37. //入口起点的最大体积 整数类型(以字节为单位)
  38. maxEntrypointSize: 50000000,
  39. //生成文件的最大体积 整数类型(以字节为单位 300k)
  40. maxAssetSize: 30000000,
  41. //只给出 js 文件的性能提示
  42. assetFilter: function (assetFilename) {
  43. return assetFilename.endsWith('.js')
  44. }
  45. }
  46. const plugins = [];
  47. // 同externals一样,我们只想在生产环境下生成gzip即可
  48. if (process.env.NODE_ENV === 'production') {
  49. plugins.push(
  50. new CompressionWebpackPlugin({
  51. filename: '[path][base].gz[query]', // 生成的文件名
  52. algorithm: 'gzip', // 类型
  53. test: new RegExp('\\.(js|css)$'), // 匹配规则
  54. threshold: 10240, // 字节数 只处理比这个大的资源
  55. minRatio: 0.8, // 压缩率 只有比这个小的才会处理
  56. // 是否删除源文件,默认: false
  57. deleteOriginalAssets: false
  58. })
  59. )
  60. }
  61. config.plugins = [
  62. ...config.plugins,
  63. ...plugins
  64. ]
  65. // 增加加载 .geojson 文件的规则
  66. let rules = [{
  67. test: /\.geojson$/,
  68. loader: 'json-loader'
  69. }]
  70. config.module.rules = [
  71. ...config.module.rules,
  72. ...rules
  73. ]
  74. },
  75. productionSourceMap: false, //打包不生成js.map文件
  76. chainWebpack: (config) => {
  77. config.resolve.alias
  78. .set('@$', resolve('src'))
  79. .set('@static', resolve('public/static'))
  80. },
  81. pluginOptions: {
  82. "style-resources-loader": {
  83. preProcessor: "less",
  84. patterns: [
  85. path.resolve(__dirname, 'src/assets/less/variable.less')
  86. ]
  87. }
  88. },
  89. devServer: {
  90. port: 2118,
  91. client: {
  92. overlay: false
  93. },
  94. proxy: {
  95. '/proxy_auth': {
  96. target: 'http://121.43.55.7:10086/',
  97. changeOrigin: true,
  98. pathRewrite: {
  99. '^/proxy_auth': ''
  100. }
  101. },
  102. '/proxy_kdyjs': {
  103. target: 'http://121.43.55.7:10018/',
  104. changeOrigin: true,
  105. pathRewrite: {
  106. '^/proxy_kdyjs': ''
  107. }
  108. },
  109. '/proxy_proxy': {
  110. target: 'http://121.43.55.7:10011/',
  111. changeOrigin: true,
  112. pathRewrite: {
  113. '^/proxy_proxy': ''
  114. }
  115. },
  116. '/proxy_dms': {
  117. target: 'http://121.43.55.7:10081/',
  118. changeOrigin: true,
  119. pathRewrite: {
  120. '^/proxy_dms': ''
  121. }
  122. },
  123. '/proxy_zwdt': {
  124. target: 'https://szlszxdt.qpservice.org.cn/',
  125. changeOrigin: true,
  126. pathRewrite: {
  127. '^/proxy_zwdt': ''
  128. }
  129. },
  130. },
  131. }
  132. })