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. nodeIntegration: true,
  17. customFileProtocol: "./",
  18. builderOptions: {
  19. productName: "云上博物",
  20. asar: false,
  21. nsis: {
  22. oneClick: false,
  23. allowToChangeInstallationDirectory: true,
  24. },
  25. win: { target: "nsis", icon: "./public/imgs/icon.png" },
  26. publish: [
  27. {
  28. provider: "generic",
  29. url: "https://houseoss.4dkankan.com/project/electron-packages/js-wlg-app/",
  30. },
  31. ],
  32. },
  33. },
  34. },
  35. configureWebpack: {
  36. devtool: "source-map",
  37. resolve: {
  38. symlinks: false,
  39. alias: {
  40. "@": path.join(__dirname, "src"),
  41. },
  42. },
  43. plugins: [
  44. AutoImport({
  45. resolvers: [ElementPlusResolver()],
  46. }),
  47. Components({
  48. resolvers: [ElementPlusResolver()],
  49. }),
  50. ],
  51. },
  52. chainWebpack: (webpackConfig) => {
  53. webpackConfig.module.rules.delete("svg");
  54. webpackConfig.module
  55. .rule("svg-sprite-loader")
  56. .test(/.svg$/)
  57. .include.add(resolve("src/assets/svg"))
  58. .end()
  59. .use("svg-sprite-loader")
  60. .loader("svg-sprite-loader")
  61. .options({
  62. symbolId: "icon-[name]",
  63. });
  64. if (IS_PRODUCTION) {
  65. webpackConfig
  66. .plugin("loadshReplace")
  67. .use(new LodashModuleReplacementPlugin());
  68. webpackConfig.optimization.splitChunks({
  69. cacheGroups: {
  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. });