vue.config.js 3.1 KB

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