vue.config.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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/icon.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. limitJson: {
  64. test: /[\\/]limit\.json$/,
  65. name: "limit",
  66. chunks: "all",
  67. priority: 1,
  68. enforce: true,
  69. },
  70. common: {
  71. name: "chunk-common",
  72. chunks: "initial",
  73. minChunks: 2,
  74. // 一个入口最大的并行请求数
  75. maxInitialRequests: 4,
  76. // 形成一个新代码块最小的体积
  77. minSize: 5000,
  78. // 缓存组打包的先后优先级
  79. priority: 1,
  80. // 如果当前的 chunk 已被从 split 出来,那么将会直接复用这个 chunk 而不是重新创建一个
  81. reuseExistingChunk: true,
  82. },
  83. vendors: {
  84. name: "chunk-vendors",
  85. test: /[\\/]node_modules[\\/]/,
  86. chunks: "initial",
  87. priority: 2,
  88. reuseExistingChunk: true,
  89. // 总是为这个缓存组创建 chunks
  90. enforce: true,
  91. },
  92. elementIcons: {
  93. name: "element-icons",
  94. test: /[\\/]node_modules[\\/]@element-plus[\\/]/,
  95. chunks: "initial",
  96. priority: 3,
  97. reuseExistingChunk: true,
  98. enforce: true,
  99. },
  100. elementPlus: {
  101. name: "element-plus",
  102. test: /[\\/]node_modules[\\/]element-plus[\\/]/,
  103. chunks: "initial",
  104. priority: 3,
  105. reuseExistingChunk: true,
  106. enforce: true,
  107. },
  108. },
  109. });
  110. }
  111. },
  112. });