@rsbuild/plugin-vue 0.1.8 → 0.2.0
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 +6 -1
- package/dist/index.js +47 -2
- package/dist/index.mjs +48 -0
- package/package.json +5 -4
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 pluginVue(options?: PluginVueOptions): RsbuildPlugin;
|
|
8
13
|
|
|
9
|
-
export { PluginVueOptions, pluginVue };
|
|
14
|
+
export { PluginVueOptions, SplitVueChunkOptions, pluginVue };
|
package/dist/index.js
CHANGED
|
@@ -33,8 +33,52 @@ __export(src_exports, {
|
|
|
33
33
|
pluginVue: () => pluginVue
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(src_exports);
|
|
36
|
-
var
|
|
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 = [
|
|
57
|
+
"vue",
|
|
58
|
+
"vue-loader",
|
|
59
|
+
"@vue/shared",
|
|
60
|
+
"@vue/reactivity",
|
|
61
|
+
"@vue/runtime-dom",
|
|
62
|
+
"@vue/runtime-core"
|
|
63
|
+
];
|
|
64
|
+
}
|
|
65
|
+
if (options.router) {
|
|
66
|
+
extraGroups.router = ["vue-router"];
|
|
67
|
+
}
|
|
68
|
+
if (!Object.keys(extraGroups).length) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
chain.optimization.splitChunks({
|
|
72
|
+
...currentConfig,
|
|
73
|
+
cacheGroups: {
|
|
74
|
+
...currentConfig.cacheGroups,
|
|
75
|
+
...(0, import_shared.createCacheGroups)(extraGroups)
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// src/index.ts
|
|
38
82
|
function pluginVue(options = {}) {
|
|
39
83
|
return {
|
|
40
84
|
name: "rsbuild:vue",
|
|
@@ -52,7 +96,7 @@ function pluginVue(options = {}) {
|
|
|
52
96
|
});
|
|
53
97
|
api.modifyBundlerChain(async (chain, { CHAIN_ID }) => {
|
|
54
98
|
chain.resolve.extensions.add(".vue");
|
|
55
|
-
const vueLoaderOptions = (0,
|
|
99
|
+
const vueLoaderOptions = (0, import_shared2.deepmerge)(
|
|
56
100
|
{
|
|
57
101
|
compilerOptions: {
|
|
58
102
|
preserveWhitespace: false
|
|
@@ -64,6 +108,7 @@ function pluginVue(options = {}) {
|
|
|
64
108
|
chain.module.rule(CHAIN_ID.RULE.VUE).test(/\.vue$/).use(CHAIN_ID.USE.VUE).loader(require.resolve("vue-loader")).options(vueLoaderOptions);
|
|
65
109
|
chain.plugin(CHAIN_ID.PLUGIN.VUE_LOADER_PLUGIN).use(import_vue_loader.VueLoaderPlugin);
|
|
66
110
|
});
|
|
111
|
+
applySplitChunksRule(api, options.splitChunks);
|
|
67
112
|
}
|
|
68
113
|
};
|
|
69
114
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -17,6 +17,53 @@ 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 = [
|
|
42
|
+
"vue",
|
|
43
|
+
"vue-loader",
|
|
44
|
+
"@vue/shared",
|
|
45
|
+
"@vue/reactivity",
|
|
46
|
+
"@vue/runtime-dom",
|
|
47
|
+
"@vue/runtime-core"
|
|
48
|
+
];
|
|
49
|
+
}
|
|
50
|
+
if (options.router) {
|
|
51
|
+
extraGroups.router = ["vue-router"];
|
|
52
|
+
}
|
|
53
|
+
if (!Object.keys(extraGroups).length) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
chain.optimization.splitChunks({
|
|
57
|
+
...currentConfig,
|
|
58
|
+
cacheGroups: {
|
|
59
|
+
...currentConfig.cacheGroups,
|
|
60
|
+
...createCacheGroups(extraGroups)
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// src/index.ts
|
|
20
67
|
function pluginVue(options = {}) {
|
|
21
68
|
return {
|
|
22
69
|
name: "rsbuild:vue",
|
|
@@ -46,6 +93,7 @@ function pluginVue(options = {}) {
|
|
|
46
93
|
chain.module.rule(CHAIN_ID.RULE.VUE).test(/\.vue$/).use(CHAIN_ID.USE.VUE).loader(__require.resolve("vue-loader")).options(vueLoaderOptions);
|
|
47
94
|
chain.plugin(CHAIN_ID.PLUGIN.VUE_LOADER_PLUGIN).use(VueLoaderPlugin);
|
|
48
95
|
});
|
|
96
|
+
applySplitChunksRule(api, options.splitChunks);
|
|
49
97
|
}
|
|
50
98
|
};
|
|
51
99
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/plugin-vue",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Vue 3 plugin of Rsbuild",
|
|
5
5
|
"homepage": "https://rsbuild.dev",
|
|
6
6
|
"repository": {
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"directory": "packages/plugin-vue"
|
|
10
10
|
},
|
|
11
11
|
"license": "MIT",
|
|
12
|
+
"type": "commonjs",
|
|
12
13
|
"exports": {
|
|
13
14
|
".": {
|
|
14
15
|
"types": "./dist/index.d.ts",
|
|
@@ -24,13 +25,13 @@
|
|
|
24
25
|
"dependencies": {
|
|
25
26
|
"vue-loader": "^17.2.2",
|
|
26
27
|
"webpack": "^5.89.0",
|
|
27
|
-
"@rsbuild/shared": "0.
|
|
28
|
+
"@rsbuild/shared": "0.2.0"
|
|
28
29
|
},
|
|
29
30
|
"devDependencies": {
|
|
30
31
|
"typescript": "^5.3.0",
|
|
31
32
|
"webpack": "^5.89.0",
|
|
32
|
-
"@rsbuild/
|
|
33
|
-
"@rsbuild/
|
|
33
|
+
"@rsbuild/test-helper": "0.2.0",
|
|
34
|
+
"@rsbuild/core": "0.2.0"
|
|
34
35
|
},
|
|
35
36
|
"peerDependencies": {
|
|
36
37
|
"@rsbuild/core": "0.x"
|