vue.config.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. const { defineConfig } = require("@vue/cli-service");
  2. // const path = require("path");
  3. const BundleAnalyzerPlugin =
  4. require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
  5. // const CompressionWebpackPlugin = require("compression-webpack-plugin");
  6. module.exports = defineConfig({
  7. // transpileDependencies: true,
  8. lintOnSave: false,
  9. devServer: {
  10. host: "0.0.0.0",
  11. port: 8003,
  12. open: true,
  13. hot: true,
  14. //使用setupMiddleware来设置mock数据
  15. // setupMiddlewares: (middlewares, devServer) => {
  16. // return mockServer(middlewares, devServer);
  17. // },
  18. proxy: {
  19. "/api": {
  20. target: "http://121.40.252.139:8089",
  21. changeOrigin: true, // //开启代理:在本地会创建一个虚拟服务端,然后发送请求的数据,并同时接收请求的数据,这样客户端端和服务端进行数据的交互就不会有跨域问题
  22. ws: true,
  23. pathRewrite: {
  24. //// 思路是如果是开发环境,就给所有要代理的接口统一加上前缀,然后代理请求时再统一通过rewrite去掉
  25. "^/api": "",
  26. },
  27. },
  28. },
  29. },
  30. chainWebpack: (config) => {
  31. config.plugin("webpack-bundle-analyzer").use(BundleAnalyzerPlugin);
  32. // 修改src目录的默认路径
  33. // config.resolve.alias.set("@", path.resolve(__dirname, "src"));
  34. // // 添加新的入口文件和分块规则
  35. // config.entry("app").clear().add("./src/main.js");
  36. // config.optimization.splitChunks({
  37. // cacheGroups: {
  38. // // 创建一个新的块,用于处理src目录下的文件
  39. // src: {
  40. // test: /[\\/]src[\\/]/,
  41. // name: "src",
  42. // chunks: "all",
  43. // priority: 10,
  44. // enforce: true,
  45. // },
  46. // },
  47. // });
  48. // config.plugin("compression").use(CompressionWebpackPlugin, [
  49. // {
  50. // filename: "[path][base].gz",
  51. // algorithm: "gzip",
  52. // test: /\.(js|css|json|txt|html|ico|svg)(\?.*)?$/i,
  53. // threshold: 10240,
  54. // minRatio: 0.8,
  55. // deleteOriginalAssets: false,
  56. // },
  57. // ]);
  58. },
  59. // 优化因为vuetify导致的打包后chunk-vendors.js过大的问题
  60. // configureWebpack: {
  61. // optimization: {
  62. // splitChunks: {
  63. // cacheGroups: {
  64. // vuetify: {
  65. // test: /[\\/]node_modules[\\/]vuetify[\\/]/,
  66. // name: "vuetify",
  67. // chunks: "all",
  68. // },
  69. // },
  70. // },
  71. // },
  72. // },
  73. // productionSourceMap: true,
  74. //拆分过大的js,优化加载速度
  75. configureWebpack: {
  76. // devtool: "cheap-module-source-map",
  77. externals: {
  78. // vue: "Vue",
  79. // vuex: "Vuex",
  80. // "vue-router": "VueRouter",
  81. // axios: "axios",
  82. // "element-ui": "ELEMENT",
  83. },
  84. optimization: {
  85. splitChunks: {
  86. chunks: "all",
  87. minSize: 60000,
  88. minRemainingSize: 0,
  89. maxSize: 100000,
  90. minChunks: 1,
  91. maxAsyncRequests: 6,
  92. maxInitialRequests: 4,
  93. enforceSizeThreshold: 50000,
  94. cacheGroups: {
  95. vendors: {
  96. // 打包除了element-ui之外的其他第三方库
  97. test: /[\\/]node_modules[\\/](?!element-ui)/,
  98. priority: -10,
  99. minSize: 30000,
  100. maxSize: 60000,
  101. },
  102. common: {
  103. // 打包src目录下的代码
  104. test: /[\\/]src[\\/]/,
  105. priority: -20,
  106. minSize: 20000,
  107. maxSize: 40000,
  108. },
  109. },
  110. },
  111. },
  112. },
  113. });