@rsbuild/plugin-vue2 0.1.9 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,9 +1,14 @@
1
1
  import { RsbuildPlugin } from '@rsbuild/core';
2
2
  import { VueLoaderOptions } from 'vue-loader';
3
3
 
4
+ type SplitVueChunkOptions = {
5
+ vue?: boolean;
6
+ router?: boolean;
7
+ };
4
8
  type PluginVueOptions = {
5
9
  vueLoaderOptions?: VueLoaderOptions;
10
+ splitChunks?: SplitVueChunkOptions;
6
11
  };
7
12
  declare function pluginVue2(options?: PluginVueOptions): RsbuildPlugin;
8
13
 
9
- export { PluginVueOptions, pluginVue2 };
14
+ export { PluginVueOptions, SplitVueChunkOptions, pluginVue2 };
package/dist/index.js CHANGED
@@ -33,15 +33,52 @@ __export(src_exports, {
33
33
  pluginVue2: () => pluginVue2
34
34
  });
35
35
  module.exports = __toCommonJS(src_exports);
36
- var import_shared = require("@rsbuild/shared");
36
+ var import_shared2 = require("@rsbuild/shared");
37
37
  var import_vue_loader = require("vue-loader");
38
+
39
+ // src/splitChunks.ts
40
+ var import_shared = require("@rsbuild/shared");
41
+ var applySplitChunksRule = (api, options = {
42
+ vue: true,
43
+ router: true
44
+ }) => {
45
+ api.modifyBundlerChain((chain) => {
46
+ const config = api.getNormalizedConfig();
47
+ if (config.performance.chunkSplit.strategy !== "split-by-experience") {
48
+ return;
49
+ }
50
+ const currentConfig = chain.optimization.splitChunks.values();
51
+ if (!(0, import_shared.isPlainObject)(currentConfig)) {
52
+ return;
53
+ }
54
+ const extraGroups = {};
55
+ if (options.vue) {
56
+ extraGroups.vue = ["vue", "vue-loader"];
57
+ }
58
+ if (options.router) {
59
+ extraGroups.router = ["vue-router"];
60
+ }
61
+ if (!Object.keys(extraGroups).length) {
62
+ return;
63
+ }
64
+ chain.optimization.splitChunks({
65
+ ...currentConfig,
66
+ cacheGroups: {
67
+ ...currentConfig.cacheGroups,
68
+ ...(0, import_shared.createCacheGroups)(extraGroups)
69
+ }
70
+ });
71
+ });
72
+ };
73
+
74
+ // src/index.ts
38
75
  function pluginVue2(options = {}) {
39
76
  return {
40
77
  name: "rsbuild:vue2",
41
78
  setup(api) {
42
79
  api.modifyBundlerChain((chain, { CHAIN_ID }) => {
43
80
  chain.resolve.extensions.add(".vue");
44
- const vueLoaderOptions = (0, import_shared.deepmerge)(
81
+ const vueLoaderOptions = (0, import_shared2.deepmerge)(
45
82
  {
46
83
  compilerOptions: {
47
84
  preserveWhitespace: false
@@ -53,6 +90,7 @@ function pluginVue2(options = {}) {
53
90
  chain.module.rule(CHAIN_ID.RULE.VUE).test(/\.vue$/).use(CHAIN_ID.USE.VUE).loader(require.resolve("vue-loader")).options(vueLoaderOptions);
54
91
  chain.plugin(CHAIN_ID.PLUGIN.VUE_LOADER_PLUGIN).use(import_vue_loader.VueLoaderPlugin);
55
92
  });
93
+ applySplitChunksRule(api, options.splitChunks);
56
94
  }
57
95
  };
58
96
  }
package/dist/index.mjs CHANGED
@@ -17,6 +17,46 @@ global.require = createRequire(import.meta.url);
17
17
  // src/index.ts
18
18
  import { deepmerge } from "@rsbuild/shared";
19
19
  import { VueLoaderPlugin } from "vue-loader";
20
+
21
+ // src/splitChunks.ts
22
+ import {
23
+ isPlainObject,
24
+ createCacheGroups
25
+ } from "@rsbuild/shared";
26
+ var applySplitChunksRule = (api, options = {
27
+ vue: true,
28
+ router: true
29
+ }) => {
30
+ api.modifyBundlerChain((chain) => {
31
+ const config = api.getNormalizedConfig();
32
+ if (config.performance.chunkSplit.strategy !== "split-by-experience") {
33
+ return;
34
+ }
35
+ const currentConfig = chain.optimization.splitChunks.values();
36
+ if (!isPlainObject(currentConfig)) {
37
+ return;
38
+ }
39
+ const extraGroups = {};
40
+ if (options.vue) {
41
+ extraGroups.vue = ["vue", "vue-loader"];
42
+ }
43
+ if (options.router) {
44
+ extraGroups.router = ["vue-router"];
45
+ }
46
+ if (!Object.keys(extraGroups).length) {
47
+ return;
48
+ }
49
+ chain.optimization.splitChunks({
50
+ ...currentConfig,
51
+ cacheGroups: {
52
+ ...currentConfig.cacheGroups,
53
+ ...createCacheGroups(extraGroups)
54
+ }
55
+ });
56
+ });
57
+ };
58
+
59
+ // src/index.ts
20
60
  function pluginVue2(options = {}) {
21
61
  return {
22
62
  name: "rsbuild:vue2",
@@ -35,6 +75,7 @@ function pluginVue2(options = {}) {
35
75
  chain.module.rule(CHAIN_ID.RULE.VUE).test(/\.vue$/).use(CHAIN_ID.USE.VUE).loader(__require.resolve("vue-loader")).options(vueLoaderOptions);
36
76
  chain.plugin(CHAIN_ID.PLUGIN.VUE_LOADER_PLUGIN).use(VueLoaderPlugin);
37
77
  });
78
+ applySplitChunksRule(api, options.splitChunks);
38
79
  }
39
80
  };
40
81
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-vue2",
3
- "version": "0.1.9",
3
+ "version": "0.2.1",
4
4
  "description": "Vue 2 plugin of Rsbuild",
5
5
  "homepage": "https://rsbuild.dev",
6
6
  "repository": {
@@ -25,13 +25,13 @@
25
25
  "dependencies": {
26
26
  "vue-loader": "^15.11.1",
27
27
  "webpack": "^5.89.0",
28
- "@rsbuild/shared": "0.1.9"
28
+ "@rsbuild/shared": "0.2.1"
29
29
  },
30
30
  "devDependencies": {
31
31
  "typescript": "^5.3.0",
32
32
  "webpack": "^5.89.0",
33
- "@rsbuild/core": "0.1.9",
34
- "@rsbuild/test-helper": "0.1.9"
33
+ "@rsbuild/core": "0.2.1",
34
+ "@rsbuild/test-helper": "0.2.1"
35
35
  },
36
36
  "peerDependencies": {
37
37
  "@rsbuild/core": "0.x"