vue.config.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. // 分析模块
  32. // config.plugin("webpack-bundle-analyzer").use(BundleAnalyzerPlugin);
  33. // 修改src目录的默认路径
  34. // config.resolve.alias.set("@", path.resolve(__dirname, "src"));
  35. // // 添加新的入口文件和分块规则
  36. // config.entry("app").clear().add("./src/main.js");
  37. // config.optimization.splitChunks({
  38. // cacheGroups: {
  39. // // 创建一个新的块,用于处理src目录下的文件
  40. // src: {
  41. // test: /[\\/]src[\\/]/,
  42. // name: "src",
  43. // chunks: "all",
  44. // priority: 10,
  45. // enforce: true,
  46. // },
  47. // },
  48. // });
  49. // config.plugin("compression").use(CompressionWebpackPlugin, [
  50. // {
  51. // filename: "[path][base].gz",
  52. // algorithm: "gzip",
  53. // test: /\.(js|css|json|txt|html|ico|svg)(\?.*)?$/i,
  54. // threshold: 10240,
  55. // minRatio: 0.8,
  56. // deleteOriginalAssets: false,
  57. // },
  58. // ]);
  59. },
  60. // 优化因为vuetify导致的打包后chunk-vendors.js过大的问题
  61. // configureWebpack: {
  62. // optimization: {
  63. // splitChunks: {
  64. // cacheGroups: {
  65. // vuetify: {
  66. // test: /[\\/]node_modules[\\/]vuetify[\\/]/,
  67. // name: "vuetify",
  68. // chunks: "all",
  69. // },
  70. // },
  71. // },
  72. // },
  73. // },
  74. // productionSourceMap: true,
  75. //拆分过大的js,优化加载速度
  76. configureWebpack: {
  77. // devtool: "cheap-module-source-map",
  78. externals: {
  79. // vue: "Vue",
  80. // vuex: "Vuex",
  81. // "vue-router": "VueRouter",
  82. // axios: "axios",
  83. // "element-ui": "ELEMENT",
  84. },
  85. optimization: {
  86. splitChunks: {
  87. chunks: "all",
  88. minSize: 60000,
  89. minRemainingSize: 0,
  90. maxSize: 100000,
  91. minChunks: 1,
  92. maxAsyncRequests: 6,
  93. maxInitialRequests: 4,
  94. enforceSizeThreshold: 50000,
  95. cacheGroups: {
  96. vendors: {
  97. // 打包除了element-ui之外的其他第三方库
  98. test: /[\\/]node_modules[\\/](?!element-ui)/,
  99. priority: -10,
  100. minSize: 30000,
  101. maxSize: 60000,
  102. },
  103. common: {
  104. // 打包src目录下的代码
  105. test: /[\\/]src[\\/]/,
  106. priority: -20,
  107. minSize: 20000,
  108. maxSize: 40000,
  109. },
  110. },
  111. },
  112. },
  113. },
  114. });