vue.config.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. const { defineConfig } = require("@vue/cli-service");
  2. const path = require("path");
  3. const webpack = require("webpack");
  4. const CompressionWebpackPlugin = require("compression-webpack-plugin");
  5. function resolve(dir) {
  6. return path.join(__dirname, dir);
  7. }
  8. module.exports = defineConfig({
  9. transpileDependencies: true,
  10. pages: {
  11. index: {
  12. // page 的入口
  13. entry: "src/main.js",
  14. // 模板来源
  15. template: "public/index.html",
  16. // 在 dist/index.html 的输出
  17. filename: "index.html",
  18. // 当使用 title 选项时,
  19. // template 中的 title 标签需要是 <title><%= htmlWebpackPlugin.options.title %></title>
  20. title: "青浦区“一张图”区级节点",
  21. // 在这个页面中包含的块,默认情况下会包含
  22. // 提取出来的通用 chunk 和 vendor chunk。
  23. chunks: ["chunk-vendors", "chunk-common", "index"],
  24. },
  25. },
  26. // ...other config
  27. configureWebpack: (config) => {
  28. config.performance = {
  29. hints: "warning",
  30. //入口起点的最大体积 整数类型(以字节为单位)
  31. maxEntrypointSize: 50000000,
  32. //生成文件的最大体积 整数类型(以字节为单位 300k)
  33. maxAssetSize: 30000000,
  34. //只给出 js 文件的性能提示
  35. assetFilter: function (assetFilename) {
  36. return assetFilename.endsWith(".js");
  37. },
  38. };
  39. const plugins = [];
  40. // 同externals一样,我们只想在生产环境下生成gzip即可
  41. if (process.env.NODE_ENV === "production") {
  42. plugins.push(
  43. new CompressionWebpackPlugin({
  44. filename: "[path][base].gz[query]", // 生成的文件名
  45. algorithm: "gzip", // 类型
  46. test: new RegExp("\\.(js|css)$"), // 匹配规则
  47. threshold: 10240, // 字节数 只处理比这个大的资源
  48. minRatio: 0.8, // 压缩率 只有比这个小的才会处理
  49. // 是否删除源文件,默认: false
  50. deleteOriginalAssets: false,
  51. })
  52. );
  53. }
  54. config.plugins = [...config.plugins, ...plugins];
  55. // 增加加载 .geojson 文件的规则
  56. let rules = [
  57. {
  58. test: /\.geojson$/,
  59. loader: "json-loader",
  60. },
  61. ];
  62. config.module.rules = [...config.module.rules, ...rules];
  63. },
  64. productionSourceMap: false, //打包不生成js.map文件
  65. chainWebpack: (config) => {
  66. config.resolve.alias.set("@$", resolve("src")).set("@static", resolve("public/static"));
  67. },
  68. devServer: {
  69. port: 2027,
  70. client: {
  71. overlay: false,
  72. },
  73. proxy: {
  74. "/proxy_oauth/": {
  75. target: "http://121.43.55.7:10086/oauth",
  76. changeOrigin: true,
  77. pathRewrite: {
  78. "^/proxy_oauth": "",
  79. },
  80. },
  81. "/proxy_dms/": {
  82. target: "http://121.43.55.7:10081/dms",
  83. changeOrigin: true,
  84. pathRewrite: {
  85. "^/proxy_dms": "",
  86. },
  87. },
  88. "/oneMap/": {
  89. // 本地环境
  90. // target: 'http://127.0.0.1:10099/qpyzt',
  91. // 线上环境
  92. target: "http://121.43.55.7:13901/qpyzt",
  93. changeOrigin: true,
  94. pathRewrite: {
  95. "^/oneMap": "",
  96. },
  97. },
  98. },
  99. },
  100. });