@rsbuild/plugin-vue2 0.0.0-nightly-20231112160816 → 0.0.0-nightly-20240114070311

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/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  # Rsbuild
6
6
 
7
- Unleash the power of Rspack with the out-of-the-box build tool.
7
+ The Rspack-based build tool. It's fast, out-of-the-box and extensible.
8
8
 
9
9
  ## Documentation
10
10
 
package/dist/index.d.ts CHANGED
@@ -1,9 +1,14 @@
1
- import { RsbuildPlugin, RsbuildPluginAPI } from '@rsbuild/core';
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
- declare function pluginVue2(options?: PluginVueOptions): RsbuildPlugin<RsbuildPluginAPI>;
12
+ declare function pluginVue2(options?: PluginVueOptions): RsbuildPlugin;
8
13
 
9
- export { PluginVueOptions, pluginVue2 };
14
+ export { PluginVueOptions, SplitVueChunkOptions, pluginVue2 };
package/dist/index.js CHANGED
@@ -33,27 +33,67 @@ __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
- name: "plugin-vue2",
77
+ name: "rsbuild:vue2",
41
78
  setup(api) {
42
79
  api.modifyBundlerChain((chain, { CHAIN_ID }) => {
43
- var _a;
44
80
  chain.resolve.extensions.add(".vue");
45
- const vueLoaderOptions = (0, import_shared.deepmerge)(
81
+ if (!chain.resolve.alias.get("vue$")) {
82
+ chain.resolve.alias.set("vue$", "vue/dist/vue.runtime.esm.js");
83
+ }
84
+ const vueLoaderOptions = (0, import_shared2.deepmerge)(
46
85
  {
47
86
  compilerOptions: {
48
87
  preserveWhitespace: false
49
88
  },
50
89
  experimentalInlineMatchResource: true
51
90
  },
52
- (_a = options.vueLoaderOptions) != null ? _a : {}
91
+ options.vueLoaderOptions ?? {}
53
92
  );
54
93
  chain.module.rule(CHAIN_ID.RULE.VUE).test(/\.vue$/).use(CHAIN_ID.USE.VUE).loader(require.resolve("vue-loader")).options(vueLoaderOptions);
55
94
  chain.plugin(CHAIN_ID.PLUGIN.VUE_LOADER_PLUGIN).use(import_vue_loader.VueLoaderPlugin);
56
95
  });
96
+ applySplitChunksRule(api, options.splitChunks);
57
97
  }
58
98
  };
59
99
  }
package/dist/index.mjs CHANGED
@@ -6,23 +6,66 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
6
6
  throw Error('Dynamic require of "' + x + '" is not supported');
7
7
  });
8
8
 
9
- // ../../node_modules/.pnpm/@modern-js+module-tools@2.40.0_typescript@5.2.2/node_modules/@modern-js/module-tools/shims/esm.js
9
+ // ../../node_modules/.pnpm/@modern-js+module-tools@2.45.0_typescript@5.3.2/node_modules/@modern-js/module-tools/shims/esm.js
10
10
  import { fileURLToPath } from "url";
11
11
  import path from "path";
12
12
 
13
- // ../../scripts/require_shims.js
13
+ // ../../scripts/requireShims.js
14
14
  import { createRequire } from "module";
15
15
  global.require = createRequire(import.meta.url);
16
16
 
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
- name: "plugin-vue2",
62
+ name: "rsbuild:vue2",
23
63
  setup(api) {
24
64
  api.modifyBundlerChain((chain, { CHAIN_ID }) => {
25
65
  chain.resolve.extensions.add(".vue");
66
+ if (!chain.resolve.alias.get("vue$")) {
67
+ chain.resolve.alias.set("vue$", "vue/dist/vue.runtime.esm.js");
68
+ }
26
69
  const vueLoaderOptions = deepmerge(
27
70
  {
28
71
  compilerOptions: {
@@ -35,6 +78,7 @@ function pluginVue2(options = {}) {
35
78
  chain.module.rule(CHAIN_ID.RULE.VUE).test(/\.vue$/).use(CHAIN_ID.USE.VUE).loader(__require.resolve("vue-loader")).options(vueLoaderOptions);
36
79
  chain.plugin(CHAIN_ID.PLUGIN.VUE_LOADER_PLUGIN).use(VueLoaderPlugin);
37
80
  });
81
+ applySplitChunksRule(api, options.splitChunks);
38
82
  }
39
83
  };
40
84
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-vue2",
3
- "version": "0.0.0-nightly-20231112160816",
3
+ "version": "0.0.0-nightly-20240114070311",
4
4
  "description": "Vue 2 plugin of Rsbuild",
5
5
  "homepage": "https://rsbuild.dev",
6
6
  "repository": {
@@ -9,6 +9,7 @@
9
9
  "directory": "packages/plugin-vue2"
10
10
  },
11
11
  "license": "MIT",
12
+ "type": "commonjs",
12
13
  "exports": {
13
14
  ".": {
14
15
  "types": "./dist/index.d.ts",
@@ -24,16 +25,16 @@
24
25
  "dependencies": {
25
26
  "vue-loader": "^15.11.1",
26
27
  "webpack": "^5.89.0",
27
- "@rsbuild/shared": "0.0.0-nightly-20231112160816"
28
+ "@rsbuild/shared": "0.0.0-nightly-20240114070311"
28
29
  },
29
30
  "devDependencies": {
30
- "typescript": "^5.2.2",
31
+ "typescript": "^5.3.0",
31
32
  "webpack": "^5.89.0",
32
- "@rsbuild/test-helper": "0.0.0-nightly-20231112160816",
33
- "@rsbuild/core": "0.0.0-nightly-20231112160816"
33
+ "@rsbuild/core": "0.0.0-nightly-20240114070311",
34
+ "@scripts/test-helper": "1.0.0"
34
35
  },
35
36
  "peerDependencies": {
36
- "@rsbuild/core": "0.0.0-nightly-20231112160816"
37
+ "@rsbuild/core": "0.0.0-nightly-20240114070311"
37
38
  },
38
39
  "publishConfig": {
39
40
  "access": "public",