vue.config.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. const { defineConfig } = require("@vue/cli-service");
  2. const path = require("path");
  3. const LodashModuleReplacementPlugin = require("lodash-webpack-plugin");
  4. const AutoImport = require("unplugin-auto-import/webpack");
  5. const Components = require("unplugin-vue-components/webpack");
  6. const { ElementPlusResolver } = require("unplugin-vue-components/resolvers");
  7. function resolve(dir) {
  8. return path.join(__dirname, ".", dir);
  9. }
  10. const IS_PRODUCTION = process.env.NODE_ENV === "production";
  11. module.exports = defineConfig({
  12. publicPath: "./",
  13. transpileDependencies: true,
  14. pluginOptions: {
  15. electronBuilder: {
  16. builderOptions: {
  17. productName: "江苏省文旅厅",
  18. asar: false,
  19. },
  20. },
  21. },
  22. configureWebpack: {
  23. devtool: "source-map",
  24. resolve: {
  25. symlinks: false,
  26. alias: {
  27. "@": path.join(__dirname, "src"),
  28. },
  29. },
  30. plugins: [
  31. AutoImport({
  32. resolvers: [ElementPlusResolver()],
  33. }),
  34. Components({
  35. resolvers: [ElementPlusResolver()],
  36. }),
  37. ],
  38. },
  39. chainWebpack: (webpackConfig) => {
  40. webpackConfig.module.rules.delete("svg");
  41. webpackConfig.module
  42. .rule("svg-sprite-loader")
  43. .test(/.svg$/)
  44. .include.add(resolve("src/assets/svg"))
  45. .end()
  46. .use("svg-sprite-loader")
  47. .loader("svg-sprite-loader")
  48. .options({
  49. symbolId: "icon-[name]",
  50. });
  51. if (IS_PRODUCTION) {
  52. webpackConfig
  53. .plugin("loadshReplace")
  54. .use(new LodashModuleReplacementPlugin());
  55. webpackConfig.optimization.splitChunks({
  56. cacheGroups: {
  57. common: {
  58. name: "chunk-common",
  59. chunks: "initial",
  60. minChunks: 2,
  61. // 一个入口最大的并行请求数
  62. maxInitialRequests: 4,
  63. // 形成一个新代码块最小的体积
  64. minSize: 5000,
  65. // 缓存组打包的先后优先级
  66. priority: 1,
  67. // 如果当前的 chunk 已被从 split 出来,那么将会直接复用这个 chunk 而不是重新创建一个
  68. reuseExistingChunk: true,
  69. },
  70. vendors: {
  71. name: "chunk-vendors",
  72. test: /[\\/]node_modules[\\/]/,
  73. chunks: "initial",
  74. priority: 2,
  75. reuseExistingChunk: true,
  76. // 总是为这个缓存组创建 chunks
  77. enforce: true,
  78. },
  79. elementIcons: {
  80. name: "element-icons",
  81. test: /[\\/]node_modules[\\/]@element-plus[\\/]/,
  82. chunks: "initial",
  83. priority: 3,
  84. reuseExistingChunk: true,
  85. enforce: true,
  86. },
  87. elementPlus: {
  88. name: "element-plus",
  89. test: /[\\/]node_modules[\\/]element-plus[\\/]/,
  90. chunks: "initial",
  91. priority: 3,
  92. reuseExistingChunk: true,
  93. enforce: true,
  94. },
  95. },
  96. });
  97. }
  98. },
  99. });