@rsbuild/plugin-vue2 1.0.1 → 1.0.3

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.
@@ -0,0 +1,8 @@
1
+ import type { Rspack } from '@rsbuild/core';
2
+ /**
3
+ * this plugin is a quick fix for issue https://github.com/web-infra-dev/rsbuild/issues/2093
4
+ */
5
+ export declare class VueLoader15PitchFixPlugin implements Rspack.RspackPluginInstance {
6
+ readonly name = "VueLoader15PitchFixPlugin";
7
+ apply(compiler: Rspack.Compiler): void;
8
+ }
package/dist/index.cjs CHANGED
@@ -1,180 +1,164 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
23
- PLUGIN_VUE2_NAME: () => PLUGIN_VUE2_NAME,
24
- pluginVue2: () => pluginVue2
2
+ const __rslib_import_meta_url__ = /*#__PURE__*/ function() {
3
+ return 'undefined' == typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
4
+ }();
5
+ var __webpack_require__ = {};
6
+ (()=>{
7
+ __webpack_require__.d = (exports1, definition)=>{
8
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
9
+ enumerable: true,
10
+ get: definition[key]
11
+ });
12
+ };
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
16
+ })();
17
+ (()=>{
18
+ __webpack_require__.r = (exports1)=>{
19
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
20
+ value: 'Module'
21
+ });
22
+ Object.defineProperty(exports1, '__esModule', {
23
+ value: true
24
+ });
25
+ };
26
+ })();
27
+ var __webpack_exports__ = {};
28
+ __webpack_require__.r(__webpack_exports__);
29
+ __webpack_require__.d(__webpack_exports__, {
30
+ PLUGIN_VUE2_NAME: ()=>PLUGIN_VUE2_NAME,
31
+ pluginVue2: ()=>pluginVue2
25
32
  });
26
- module.exports = __toCommonJS(src_exports);
27
-
28
- // node_modules/.pnpm/tsup@8.2.3_postcss@8.4.38_typescript@5.5.4/node_modules/tsup/assets/cjs_shims.js
29
- var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
30
- var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
31
-
32
- // src/index.ts
33
- var import_node_module = require("module");
34
- var import_vue_loader = require("vue-loader");
35
-
36
- // src/VueLoader15PitchFixPlugin.ts
37
- var VueLoader15PitchFixPlugin = class {
38
- constructor() {
39
- this.name = "VueLoader15PitchFixPlugin";
40
- }
41
- apply(compiler) {
42
- const { NormalModule } = compiler.webpack;
43
- compiler.hooks.compilation.tap(this.name, (compilation) => {
44
- const isExpCssOn = compilation.compiler.options?.experiments?.css;
45
- if (!isExpCssOn) return;
46
- NormalModule.getCompilationHooks(compilation).loader.tap(
47
- this.name,
48
- (loaderContext) => {
49
- if (
50
- // the related issue only happens for <style>
51
- /[?&]type=style/.test(loaderContext.resourceQuery) && // the fix should be applied before `pitch` phase completed.
52
- // once `pitch` phase completed, vue-loader will remove its pitcher loader.
53
- /[\\/]vue-loader[\\/]lib[\\/]loaders[\\/]pitcher/.test(
54
- loaderContext.loaders?.[0]?.path || ""
55
- )
56
- ) {
57
- const seen = /* @__PURE__ */ new Set();
58
- const loaders = [];
59
- for (const loader of loaderContext.loaders || []) {
60
- const identifier = typeof loader === "string" ? loader : loader.path + loader.query;
61
- if (!seen.has(identifier)) {
62
- seen.add(identifier);
63
- loaders.push(loader);
64
- }
65
- }
66
- loaderContext.loaders = loaders;
67
- }
68
- }
69
- );
33
+ const external_node_module_namespaceObject = require("node:module");
34
+ const external_vue_loader_namespaceObject = require("vue-loader");
35
+ function _define_property(obj, key, value) {
36
+ if (key in obj) Object.defineProperty(obj, key, {
37
+ value: value,
38
+ enumerable: true,
39
+ configurable: true,
40
+ writable: true
70
41
  });
71
- }
72
- };
73
-
74
- // src/splitChunks.ts
75
- var isPlainObject = (obj) => obj !== null && typeof obj === "object" && Object.prototype.toString.call(obj) === "[object Object]";
76
- var applySplitChunksRule = (api, options = {
77
- vue: true,
78
- router: true
79
- }) => {
80
- api.modifyBundlerChain((chain, { environment }) => {
81
- const { config } = environment;
82
- if (config.performance.chunkSplit.strategy !== "split-by-experience") {
83
- return;
84
- }
85
- const currentConfig = chain.optimization.splitChunks.values();
86
- if (!isPlainObject(currentConfig)) {
87
- return;
88
- }
89
- const extraGroups = {};
90
- if (options.router) {
91
- extraGroups.vue = {
92
- name: "lib-vue",
93
- test: /node_modules[\\/](?:vue|vue-loader)[\\/]/,
94
- priority: 0
95
- };
96
- }
97
- if (options.router) {
98
- extraGroups.router = {
99
- name: "lib-router",
100
- test: /node_modules[\\/]vue-router[\\/]/,
101
- priority: 0
102
- };
42
+ else obj[key] = value;
43
+ return obj;
44
+ }
45
+ class VueLoader15PitchFixPlugin {
46
+ apply(compiler) {
47
+ const { NormalModule } = compiler.webpack;
48
+ compiler.hooks.compilation.tap(this.name, (compilation)=>{
49
+ var _compilation_compiler_options_experiments, _compilation_compiler_options;
50
+ const isExpCssOn = null === (_compilation_compiler_options = compilation.compiler.options) || void 0 === _compilation_compiler_options ? void 0 : null === (_compilation_compiler_options_experiments = _compilation_compiler_options.experiments) || void 0 === _compilation_compiler_options_experiments ? void 0 : _compilation_compiler_options_experiments.css;
51
+ if (!isExpCssOn) return;
52
+ NormalModule.getCompilationHooks(compilation).loader.tap(this.name, (loaderContext)=>{
53
+ var _loaderContext_loaders_, _loaderContext_loaders;
54
+ if (/[?&]type=style/.test(loaderContext.resourceQuery) && /[\\/]vue-loader[\\/]lib[\\/]loaders[\\/]pitcher/.test((null === (_loaderContext_loaders = loaderContext.loaders) || void 0 === _loaderContext_loaders ? void 0 : null === (_loaderContext_loaders_ = _loaderContext_loaders[0]) || void 0 === _loaderContext_loaders_ ? void 0 : _loaderContext_loaders_.path) || '')) {
55
+ const seen = new Set();
56
+ const loaders = [];
57
+ for (const loader of loaderContext.loaders || []){
58
+ const identifier = 'string' == typeof loader ? loader : loader.path + loader.query;
59
+ if (!seen.has(identifier)) {
60
+ seen.add(identifier);
61
+ loaders.push(loader);
62
+ }
63
+ }
64
+ loaderContext.loaders = loaders;
65
+ }
66
+ });
67
+ });
103
68
  }
104
- if (!Object.keys(extraGroups).length) {
105
- return;
69
+ constructor(){
70
+ _define_property(this, "name", 'VueLoader15PitchFixPlugin');
106
71
  }
107
- chain.optimization.splitChunks({
108
- ...currentConfig,
109
- cacheGroups: {
110
- ...currentConfig.cacheGroups,
111
- ...extraGroups
112
- }
72
+ }
73
+ const isPlainObject = (obj)=>null !== obj && 'object' == typeof obj && '[object Object]' === Object.prototype.toString.call(obj);
74
+ const applySplitChunksRule = (api, options = {
75
+ vue: true,
76
+ router: true
77
+ })=>{
78
+ api.modifyBundlerChain((chain, { environment })=>{
79
+ const { config } = environment;
80
+ if ('split-by-experience' !== config.performance.chunkSplit.strategy) return;
81
+ const currentConfig = chain.optimization.splitChunks.values();
82
+ if (!isPlainObject(currentConfig)) return;
83
+ const extraGroups = {};
84
+ if (options.vue) extraGroups.vue = {
85
+ name: 'lib-vue',
86
+ test: /node_modules[\\/](?:vue|vue-loader)[\\/]/,
87
+ priority: 0
88
+ };
89
+ if (options.router) extraGroups.router = {
90
+ name: 'lib-router',
91
+ test: /node_modules[\\/]vue-router[\\/]/,
92
+ priority: 0
93
+ };
94
+ if (!Object.keys(extraGroups).length) return;
95
+ chain.optimization.splitChunks({
96
+ ...currentConfig,
97
+ cacheGroups: {
98
+ ...currentConfig.cacheGroups,
99
+ ...extraGroups
100
+ }
101
+ });
113
102
  });
114
- });
115
103
  };
116
-
117
- // src/index.ts
118
- var require2 = (0, import_node_module.createRequire)(importMetaUrl);
119
- var PLUGIN_VUE2_NAME = "rsbuild:vue2";
104
+ const src_require = (0, external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__);
105
+ const PLUGIN_VUE2_NAME = 'rsbuild:vue2';
120
106
  function pluginVue2(options = {}) {
121
- return {
122
- name: PLUGIN_VUE2_NAME,
123
- setup(api) {
124
- const VUE_REGEXP = /\.vue$/;
125
- const CSS_MODULES_REGEX = /\.modules?\.\w+$/i;
126
- api.modifyEnvironmentConfig((config) => {
127
- if (config.output.cssModules.auto === true) {
128
- config.output.cssModules.auto = (path, query) => {
129
- if (VUE_REGEXP.test(path)) {
130
- return query.includes("type=style") && query.includes("module=true");
131
- }
132
- return CSS_MODULES_REGEX.test(path);
133
- };
134
- }
135
- return config;
136
- });
137
- api.modifyBundlerChain((chain, { CHAIN_ID }) => {
138
- chain.resolve.extensions.add(".vue");
139
- if (!chain.resolve.alias.get("vue$")) {
140
- chain.resolve.alias.set("vue$", "vue/dist/vue.runtime.esm.js");
107
+ return {
108
+ name: PLUGIN_VUE2_NAME,
109
+ setup (api) {
110
+ const VUE_REGEXP = /\.vue$/;
111
+ const CSS_MODULES_REGEX = /\.modules?\.\w+$/i;
112
+ api.modifyEnvironmentConfig((config, { mergeEnvironmentConfig })=>{
113
+ if (true === config.output.cssModules.auto) config.output.cssModules.auto = (path, query)=>{
114
+ if (VUE_REGEXP.test(path)) return query.includes('type=style') && query.includes('module=true');
115
+ return CSS_MODULES_REGEX.test(path);
116
+ };
117
+ const extraConfig = {
118
+ source: {
119
+ include: [
120
+ /\.vue/
121
+ ]
122
+ }
123
+ };
124
+ return mergeEnvironmentConfig(config, extraConfig);
125
+ });
126
+ api.modifyBundlerChain((chain, { CHAIN_ID })=>{
127
+ chain.resolve.extensions.add('.vue');
128
+ if (!chain.resolve.alias.get('vue$')) chain.resolve.alias.set('vue$', 'vue/dist/vue.runtime.esm.js');
129
+ const userLoaderOptions = options.vueLoaderOptions ?? {};
130
+ const compilerOptions = {
131
+ whitespace: 'condense',
132
+ ...userLoaderOptions.compilerOptions
133
+ };
134
+ const vueLoaderOptions = {
135
+ experimentalInlineMatchResource: true,
136
+ ...userLoaderOptions,
137
+ compilerOptions
138
+ };
139
+ const rule = chain.module.rule(CHAIN_ID.RULE.VUE);
140
+ rule.test(VUE_REGEXP).use(CHAIN_ID.USE.VUE).loader(src_require.resolve('vue-loader')).options(vueLoaderOptions);
141
+ if (chain.module.rules.has(CHAIN_ID.RULE.JS)) applyResolveConfig(rule, chain.module.rule(CHAIN_ID.RULE.JS));
142
+ chain.module.rule(CHAIN_ID.RULE.CSS).test(/\.(?:css|postcss|pcss)$/);
143
+ chain.plugin(CHAIN_ID.PLUGIN.VUE_LOADER_PLUGIN).use(external_vue_loader_namespaceObject.VueLoaderPlugin);
144
+ chain.plugin('vue-loader-15-pitch-fix').use(VueLoader15PitchFixPlugin);
145
+ });
146
+ applySplitChunksRule(api, options.splitChunks);
141
147
  }
142
- const userLoaderOptions = options.vueLoaderOptions ?? {};
143
- const compilerOptions = {
144
- // https://github.com/vuejs/vue-cli/pull/3853
145
- whitespace: "condense",
146
- ...userLoaderOptions.compilerOptions
147
- };
148
- const vueLoaderOptions = {
149
- experimentalInlineMatchResource: true,
150
- ...userLoaderOptions,
151
- compilerOptions
152
- };
153
- const rule = chain.module.rule(CHAIN_ID.RULE.VUE);
154
- rule.test(VUE_REGEXP).use(CHAIN_ID.USE.VUE).loader(require2.resolve("vue-loader")).options(vueLoaderOptions);
155
- if (chain.module.rules.has(CHAIN_ID.RULE.JS)) {
156
- applyResolveConfig(rule, chain.module.rule(CHAIN_ID.RULE.JS));
157
- }
158
- chain.module.rule(CHAIN_ID.RULE.CSS).test(/\.(?:css|postcss|pcss)$/);
159
- chain.plugin(CHAIN_ID.PLUGIN.VUE_LOADER_PLUGIN).use(import_vue_loader.VueLoaderPlugin);
160
- chain.plugin("vue-loader-15-pitch-fix").use(VueLoader15PitchFixPlugin);
161
- });
162
- applySplitChunksRule(api, options.splitChunks);
163
- }
164
- };
148
+ };
165
149
  }
166
150
  function applyResolveConfig(vueRule, jsRule) {
167
- const fullySpecified = jsRule.resolve.get("fullySpecified");
168
- const aliases = jsRule.resolve.alias.entries();
169
- if (aliases) {
170
- vueRule.resolve.alias.merge(aliases);
171
- }
172
- if (fullySpecified !== void 0) {
173
- vueRule.resolve.fullySpecified(fullySpecified);
174
- }
151
+ const fullySpecified = jsRule.resolve.get('fullySpecified');
152
+ const aliases = jsRule.resolve.alias.entries();
153
+ if (aliases) vueRule.resolve.alias.merge(aliases);
154
+ if (void 0 !== fullySpecified) vueRule.resolve.fullySpecified(fullySpecified);
175
155
  }
176
- // Annotate the CommonJS export names for ESM import in node:
177
- 0 && (module.exports = {
178
- PLUGIN_VUE2_NAME,
179
- pluginVue2
156
+ exports.PLUGIN_VUE2_NAME = __webpack_exports__.PLUGIN_VUE2_NAME;
157
+ exports.pluginVue2 = __webpack_exports__.pluginVue2;
158
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
159
+ "PLUGIN_VUE2_NAME",
160
+ "pluginVue2"
161
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
162
+ Object.defineProperty(exports, '__esModule', {
163
+ value: true
180
164
  });
package/dist/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
- import { RsbuildPlugin } from '@rsbuild/core';
2
- import { VueLoaderOptions } from 'vue-loader';
3
-
4
- type SplitVueChunkOptions = {
1
+ import type { RsbuildPlugin } from '@rsbuild/core';
2
+ import { type VueLoaderOptions } from 'vue-loader';
3
+ export type SplitVueChunkOptions = {
5
4
  /**
6
5
  * Whether to enable split chunking for Vue-related dependencies (e.g., vue, vue-loader).
7
6
  * @default true
@@ -13,7 +12,7 @@ type SplitVueChunkOptions = {
13
12
  */
14
13
  router?: boolean;
15
14
  };
16
- type PluginVueOptions = {
15
+ export type PluginVueOptions = {
17
16
  /**
18
17
  * Options passed to `vue-loader`.
19
18
  * @see https://vue-loader.vuejs.org/
@@ -24,7 +23,5 @@ type PluginVueOptions = {
24
23
  */
25
24
  splitChunks?: SplitVueChunkOptions;
26
25
  };
27
- declare const PLUGIN_VUE2_NAME = "rsbuild:vue2";
28
- declare function pluginVue2(options?: PluginVueOptions): RsbuildPlugin;
29
-
30
- export { PLUGIN_VUE2_NAME, type PluginVueOptions, type SplitVueChunkOptions, pluginVue2 };
26
+ export declare const PLUGIN_VUE2_NAME = "rsbuild:vue2";
27
+ export declare function pluginVue2(options?: PluginVueOptions): RsbuildPlugin;
package/dist/index.js CHANGED
@@ -1,148 +1,124 @@
1
- // src/index.ts
2
- import { createRequire } from "node:module";
3
- import { VueLoaderPlugin } from "vue-loader";
4
-
5
- // src/VueLoader15PitchFixPlugin.ts
6
- var VueLoader15PitchFixPlugin = class {
7
- constructor() {
8
- this.name = "VueLoader15PitchFixPlugin";
9
- }
10
- apply(compiler) {
11
- const { NormalModule } = compiler.webpack;
12
- compiler.hooks.compilation.tap(this.name, (compilation) => {
13
- const isExpCssOn = compilation.compiler.options?.experiments?.css;
14
- if (!isExpCssOn) return;
15
- NormalModule.getCompilationHooks(compilation).loader.tap(
16
- this.name,
17
- (loaderContext) => {
18
- if (
19
- // the related issue only happens for <style>
20
- /[?&]type=style/.test(loaderContext.resourceQuery) && // the fix should be applied before `pitch` phase completed.
21
- // once `pitch` phase completed, vue-loader will remove its pitcher loader.
22
- /[\\/]vue-loader[\\/]lib[\\/]loaders[\\/]pitcher/.test(
23
- loaderContext.loaders?.[0]?.path || ""
24
- )
25
- ) {
26
- const seen = /* @__PURE__ */ new Set();
27
- const loaders = [];
28
- for (const loader of loaderContext.loaders || []) {
29
- const identifier = typeof loader === "string" ? loader : loader.path + loader.query;
30
- if (!seen.has(identifier)) {
31
- seen.add(identifier);
32
- loaders.push(loader);
33
- }
34
- }
35
- loaderContext.loaders = loaders;
36
- }
37
- }
38
- );
1
+ import * as __WEBPACK_EXTERNAL_MODULE_node_module_ab9f2194__ from "node:module";
2
+ import * as __WEBPACK_EXTERNAL_MODULE_vue_loader_a33e643c__ from "vue-loader";
3
+ function _define_property(obj, key, value) {
4
+ if (key in obj) Object.defineProperty(obj, key, {
5
+ value: value,
6
+ enumerable: true,
7
+ configurable: true,
8
+ writable: true
39
9
  });
40
- }
41
- };
42
-
43
- // src/splitChunks.ts
44
- var isPlainObject = (obj) => obj !== null && typeof obj === "object" && Object.prototype.toString.call(obj) === "[object Object]";
45
- var applySplitChunksRule = (api, options = {
46
- vue: true,
47
- router: true
48
- }) => {
49
- api.modifyBundlerChain((chain, { environment }) => {
50
- const { config } = environment;
51
- if (config.performance.chunkSplit.strategy !== "split-by-experience") {
52
- return;
53
- }
54
- const currentConfig = chain.optimization.splitChunks.values();
55
- if (!isPlainObject(currentConfig)) {
56
- return;
57
- }
58
- const extraGroups = {};
59
- if (options.router) {
60
- extraGroups.vue = {
61
- name: "lib-vue",
62
- test: /node_modules[\\/](?:vue|vue-loader)[\\/]/,
63
- priority: 0
64
- };
65
- }
66
- if (options.router) {
67
- extraGroups.router = {
68
- name: "lib-router",
69
- test: /node_modules[\\/]vue-router[\\/]/,
70
- priority: 0
71
- };
10
+ else obj[key] = value;
11
+ return obj;
12
+ }
13
+ class VueLoader15PitchFixPlugin {
14
+ apply(compiler) {
15
+ const { NormalModule } = compiler.webpack;
16
+ compiler.hooks.compilation.tap(this.name, (compilation)=>{
17
+ var _compilation_compiler_options_experiments, _compilation_compiler_options;
18
+ const isExpCssOn = null === (_compilation_compiler_options = compilation.compiler.options) || void 0 === _compilation_compiler_options ? void 0 : null === (_compilation_compiler_options_experiments = _compilation_compiler_options.experiments) || void 0 === _compilation_compiler_options_experiments ? void 0 : _compilation_compiler_options_experiments.css;
19
+ if (!isExpCssOn) return;
20
+ NormalModule.getCompilationHooks(compilation).loader.tap(this.name, (loaderContext)=>{
21
+ var _loaderContext_loaders_, _loaderContext_loaders;
22
+ if (/[?&]type=style/.test(loaderContext.resourceQuery) && /[\\/]vue-loader[\\/]lib[\\/]loaders[\\/]pitcher/.test((null === (_loaderContext_loaders = loaderContext.loaders) || void 0 === _loaderContext_loaders ? void 0 : null === (_loaderContext_loaders_ = _loaderContext_loaders[0]) || void 0 === _loaderContext_loaders_ ? void 0 : _loaderContext_loaders_.path) || '')) {
23
+ const seen = new Set();
24
+ const loaders = [];
25
+ for (const loader of loaderContext.loaders || []){
26
+ const identifier = 'string' == typeof loader ? loader : loader.path + loader.query;
27
+ if (!seen.has(identifier)) {
28
+ seen.add(identifier);
29
+ loaders.push(loader);
30
+ }
31
+ }
32
+ loaderContext.loaders = loaders;
33
+ }
34
+ });
35
+ });
72
36
  }
73
- if (!Object.keys(extraGroups).length) {
74
- return;
37
+ constructor(){
38
+ _define_property(this, "name", 'VueLoader15PitchFixPlugin');
75
39
  }
76
- chain.optimization.splitChunks({
77
- ...currentConfig,
78
- cacheGroups: {
79
- ...currentConfig.cacheGroups,
80
- ...extraGroups
81
- }
40
+ }
41
+ const isPlainObject = (obj)=>null !== obj && 'object' == typeof obj && '[object Object]' === Object.prototype.toString.call(obj);
42
+ const applySplitChunksRule = (api, options = {
43
+ vue: true,
44
+ router: true
45
+ })=>{
46
+ api.modifyBundlerChain((chain, { environment })=>{
47
+ const { config } = environment;
48
+ if ('split-by-experience' !== config.performance.chunkSplit.strategy) return;
49
+ const currentConfig = chain.optimization.splitChunks.values();
50
+ if (!isPlainObject(currentConfig)) return;
51
+ const extraGroups = {};
52
+ if (options.vue) extraGroups.vue = {
53
+ name: 'lib-vue',
54
+ test: /node_modules[\\/](?:vue|vue-loader)[\\/]/,
55
+ priority: 0
56
+ };
57
+ if (options.router) extraGroups.router = {
58
+ name: 'lib-router',
59
+ test: /node_modules[\\/]vue-router[\\/]/,
60
+ priority: 0
61
+ };
62
+ if (!Object.keys(extraGroups).length) return;
63
+ chain.optimization.splitChunks({
64
+ ...currentConfig,
65
+ cacheGroups: {
66
+ ...currentConfig.cacheGroups,
67
+ ...extraGroups
68
+ }
69
+ });
82
70
  });
83
- });
84
71
  };
85
-
86
- // src/index.ts
87
- var require2 = createRequire(import.meta.url);
88
- var PLUGIN_VUE2_NAME = "rsbuild:vue2";
72
+ const src_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module_ab9f2194__.createRequire)(import.meta.url);
73
+ const PLUGIN_VUE2_NAME = 'rsbuild:vue2';
89
74
  function pluginVue2(options = {}) {
90
- return {
91
- name: PLUGIN_VUE2_NAME,
92
- setup(api) {
93
- const VUE_REGEXP = /\.vue$/;
94
- const CSS_MODULES_REGEX = /\.modules?\.\w+$/i;
95
- api.modifyEnvironmentConfig((config) => {
96
- if (config.output.cssModules.auto === true) {
97
- config.output.cssModules.auto = (path, query) => {
98
- if (VUE_REGEXP.test(path)) {
99
- return query.includes("type=style") && query.includes("module=true");
100
- }
101
- return CSS_MODULES_REGEX.test(path);
102
- };
75
+ return {
76
+ name: PLUGIN_VUE2_NAME,
77
+ setup (api) {
78
+ const VUE_REGEXP = /\.vue$/;
79
+ const CSS_MODULES_REGEX = /\.modules?\.\w+$/i;
80
+ api.modifyEnvironmentConfig((config, { mergeEnvironmentConfig })=>{
81
+ if (true === config.output.cssModules.auto) config.output.cssModules.auto = (path, query)=>{
82
+ if (VUE_REGEXP.test(path)) return query.includes('type=style') && query.includes('module=true');
83
+ return CSS_MODULES_REGEX.test(path);
84
+ };
85
+ const extraConfig = {
86
+ source: {
87
+ include: [
88
+ /\.vue/
89
+ ]
90
+ }
91
+ };
92
+ return mergeEnvironmentConfig(config, extraConfig);
93
+ });
94
+ api.modifyBundlerChain((chain, { CHAIN_ID })=>{
95
+ chain.resolve.extensions.add('.vue');
96
+ if (!chain.resolve.alias.get('vue$')) chain.resolve.alias.set('vue$', 'vue/dist/vue.runtime.esm.js');
97
+ const userLoaderOptions = options.vueLoaderOptions ?? {};
98
+ const compilerOptions = {
99
+ whitespace: 'condense',
100
+ ...userLoaderOptions.compilerOptions
101
+ };
102
+ const vueLoaderOptions = {
103
+ experimentalInlineMatchResource: true,
104
+ ...userLoaderOptions,
105
+ compilerOptions
106
+ };
107
+ const rule = chain.module.rule(CHAIN_ID.RULE.VUE);
108
+ rule.test(VUE_REGEXP).use(CHAIN_ID.USE.VUE).loader(src_require.resolve('vue-loader')).options(vueLoaderOptions);
109
+ if (chain.module.rules.has(CHAIN_ID.RULE.JS)) applyResolveConfig(rule, chain.module.rule(CHAIN_ID.RULE.JS));
110
+ chain.module.rule(CHAIN_ID.RULE.CSS).test(/\.(?:css|postcss|pcss)$/);
111
+ chain.plugin(CHAIN_ID.PLUGIN.VUE_LOADER_PLUGIN).use(__WEBPACK_EXTERNAL_MODULE_vue_loader_a33e643c__.VueLoaderPlugin);
112
+ chain.plugin('vue-loader-15-pitch-fix').use(VueLoader15PitchFixPlugin);
113
+ });
114
+ applySplitChunksRule(api, options.splitChunks);
103
115
  }
104
- return config;
105
- });
106
- api.modifyBundlerChain((chain, { CHAIN_ID }) => {
107
- chain.resolve.extensions.add(".vue");
108
- if (!chain.resolve.alias.get("vue$")) {
109
- chain.resolve.alias.set("vue$", "vue/dist/vue.runtime.esm.js");
110
- }
111
- const userLoaderOptions = options.vueLoaderOptions ?? {};
112
- const compilerOptions = {
113
- // https://github.com/vuejs/vue-cli/pull/3853
114
- whitespace: "condense",
115
- ...userLoaderOptions.compilerOptions
116
- };
117
- const vueLoaderOptions = {
118
- experimentalInlineMatchResource: true,
119
- ...userLoaderOptions,
120
- compilerOptions
121
- };
122
- const rule = chain.module.rule(CHAIN_ID.RULE.VUE);
123
- rule.test(VUE_REGEXP).use(CHAIN_ID.USE.VUE).loader(require2.resolve("vue-loader")).options(vueLoaderOptions);
124
- if (chain.module.rules.has(CHAIN_ID.RULE.JS)) {
125
- applyResolveConfig(rule, chain.module.rule(CHAIN_ID.RULE.JS));
126
- }
127
- chain.module.rule(CHAIN_ID.RULE.CSS).test(/\.(?:css|postcss|pcss)$/);
128
- chain.plugin(CHAIN_ID.PLUGIN.VUE_LOADER_PLUGIN).use(VueLoaderPlugin);
129
- chain.plugin("vue-loader-15-pitch-fix").use(VueLoader15PitchFixPlugin);
130
- });
131
- applySplitChunksRule(api, options.splitChunks);
132
- }
133
- };
116
+ };
134
117
  }
135
118
  function applyResolveConfig(vueRule, jsRule) {
136
- const fullySpecified = jsRule.resolve.get("fullySpecified");
137
- const aliases = jsRule.resolve.alias.entries();
138
- if (aliases) {
139
- vueRule.resolve.alias.merge(aliases);
140
- }
141
- if (fullySpecified !== void 0) {
142
- vueRule.resolve.fullySpecified(fullySpecified);
143
- }
119
+ const fullySpecified = jsRule.resolve.get('fullySpecified');
120
+ const aliases = jsRule.resolve.alias.entries();
121
+ if (aliases) vueRule.resolve.alias.merge(aliases);
122
+ if (void 0 !== fullySpecified) vueRule.resolve.fullySpecified(fullySpecified);
144
123
  }
145
- export {
146
- PLUGIN_VUE2_NAME,
147
- pluginVue2
148
- };
124
+ export { PLUGIN_VUE2_NAME, pluginVue2 };
@@ -0,0 +1,3 @@
1
+ import type { RsbuildPluginAPI } from '@rsbuild/core';
2
+ import type { SplitVueChunkOptions } from './index.js';
3
+ export declare const applySplitChunksRule: (api: RsbuildPluginAPI, options?: SplitVueChunkOptions) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-vue2",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "repository": "https://github.com/rspack-contrib/rsbuild-plugin-vue2",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -17,6 +17,15 @@
17
17
  "files": [
18
18
  "dist"
19
19
  ],
20
+ "scripts": {
21
+ "build": "rslib build",
22
+ "dev": "rslib build --watch",
23
+ "lint": "biome check .",
24
+ "lint:write": "biome check . --write",
25
+ "prepare": "simple-git-hooks && npm run build",
26
+ "test": "playwright test",
27
+ "bump": "npx bumpp"
28
+ },
20
29
  "simple-git-hooks": {
21
30
  "pre-commit": "npx nano-staged"
22
31
  },
@@ -27,38 +36,33 @@
27
36
  },
28
37
  "dependencies": {
29
38
  "vue-loader": "^15.11.1",
30
- "webpack": "^5.93.0"
39
+ "webpack": "^5.98.0"
31
40
  },
32
41
  "devDependencies": {
33
- "@biomejs/biome": "^1.8.3",
34
- "@playwright/test": "^1.45.3",
35
- "@rsbuild/core": "^1.0.1-beta.16",
36
- "@rsbuild/plugin-less": "1.0.1-beta.16",
37
- "@types/node": "^20.14.13",
42
+ "@biomejs/biome": "^1.9.4",
43
+ "@playwright/test": "^1.51.1",
44
+ "@rsbuild/core": "^1.3.1",
45
+ "@rsbuild/plugin-less": "1.2.1",
46
+ "@rslib/core": "^0.6.1",
47
+ "@types/node": "^22.13.14",
38
48
  "nano-staged": "^0.8.0",
39
- "playwright": "^1.45.3",
40
- "simple-git-hooks": "^2.11.1",
41
- "tsup": "^8.2.3",
42
- "typescript": "^5.5.4",
43
- "vue": "^2.7.14"
49
+ "playwright": "^1.51.1",
50
+ "simple-git-hooks": "^2.12.1",
51
+ "typescript": "^5.8.2",
52
+ "vue": "^2.7.16"
44
53
  },
45
54
  "peerDependencies": {
46
- "@rsbuild/core": "1.x || ^1.0.1-beta.0"
55
+ "@rsbuild/core": "1.x"
47
56
  },
48
57
  "peerDependenciesMeta": {
49
58
  "@rsbuild/core": {
50
59
  "optional": true
51
60
  }
52
61
  },
62
+ "packageManager": "pnpm@10.7.0",
53
63
  "publishConfig": {
54
64
  "access": "public",
55
- "registry": "https://registry.npmjs.org/"
56
- },
57
- "scripts": {
58
- "build": "tsup",
59
- "dev": "tsup --watch",
60
- "lint": "biome check .",
61
- "lint:write": "biome check . --write",
62
- "test": "playwright test"
65
+ "registry": "https://registry.npmjs.org/",
66
+ "provenance": true
63
67
  }
64
- }
68
+ }
package/dist/index.d.cts DELETED
@@ -1,30 +0,0 @@
1
- import { RsbuildPlugin } from '@rsbuild/core';
2
- import { VueLoaderOptions } from 'vue-loader';
3
-
4
- type SplitVueChunkOptions = {
5
- /**
6
- * Whether to enable split chunking for Vue-related dependencies (e.g., vue, vue-loader).
7
- * @default true
8
- */
9
- vue?: boolean;
10
- /**
11
- * Whether to enable split chunking for vue-router.
12
- * @default true
13
- */
14
- router?: boolean;
15
- };
16
- type PluginVueOptions = {
17
- /**
18
- * Options passed to `vue-loader`.
19
- * @see https://vue-loader.vuejs.org/
20
- */
21
- vueLoaderOptions?: VueLoaderOptions;
22
- /**
23
- * This option is used to control the split chunks behavior.
24
- */
25
- splitChunks?: SplitVueChunkOptions;
26
- };
27
- declare const PLUGIN_VUE2_NAME = "rsbuild:vue2";
28
- declare function pluginVue2(options?: PluginVueOptions): RsbuildPlugin;
29
-
30
- export { PLUGIN_VUE2_NAME, type PluginVueOptions, type SplitVueChunkOptions, pluginVue2 };