@rsbuild/plugin-vue2 1.0.1 → 1.0.2

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,180 @@
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
+ // The require scope
3
+ var __webpack_require__ = {};
4
+ /************************************************************************/ // webpack/runtime/define_property_getters
5
+ (()=>{
6
+ __webpack_require__.d = function(exports1, definition) {
7
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
8
+ enumerable: true,
9
+ get: definition[key]
10
+ });
11
+ };
12
+ })();
13
+ // webpack/runtime/has_own_property
14
+ (()=>{
15
+ __webpack_require__.o = function(obj, prop) {
16
+ return Object.prototype.hasOwnProperty.call(obj, prop);
17
+ };
18
+ })();
19
+ // webpack/runtime/make_namespace_object
20
+ (()=>{
21
+ // define __esModule on exports
22
+ __webpack_require__.r = function(exports1) {
23
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
24
+ value: 'Module'
25
+ });
26
+ Object.defineProperty(exports1, '__esModule', {
27
+ value: true
28
+ });
29
+ };
30
+ })();
31
+ /************************************************************************/ var __webpack_exports__ = {};
32
+ // ESM COMPAT FLAG
33
+ __webpack_require__.r(__webpack_exports__);
34
+ // EXPORTS
35
+ __webpack_require__.d(__webpack_exports__, {
36
+ PLUGIN_VUE2_NAME: ()=>/* binding */ PLUGIN_VUE2_NAME,
37
+ pluginVue2: ()=>/* binding */ pluginVue2
25
38
  });
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
- );
39
+ const external_node_module_namespaceObject = require("node:module");
40
+ const external_vue_loader_namespaceObject = require("vue-loader");
41
+ function _define_property(obj, key, value) {
42
+ if (key in obj) Object.defineProperty(obj, key, {
43
+ value: value,
44
+ enumerable: true,
45
+ configurable: true,
46
+ writable: true
70
47
  });
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
- };
48
+ else obj[key] = value;
49
+ return obj;
50
+ }
51
+ /**
52
+ * this plugin is a quick fix for issue https://github.com/web-infra-dev/rsbuild/issues/2093
53
+ */ class VueLoader15PitchFixPlugin {
54
+ apply(compiler) {
55
+ const { NormalModule } = compiler.webpack;
56
+ compiler.hooks.compilation.tap(this.name, (compilation)=>{
57
+ var _compilation_compiler_options_experiments, _compilation_compiler_options;
58
+ 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;
59
+ // the related issue only happens when experiments.css is on
60
+ if (!isExpCssOn) return;
61
+ NormalModule.getCompilationHooks(compilation).loader.tap(this.name, (loaderContext)=>{
62
+ var _loaderContext_loaders_, _loaderContext_loaders;
63
+ if (/[?&]type=style/.test(loaderContext.resourceQuery) && // the fix should be applied before `pitch` phase completed.
64
+ // once `pitch` phase completed, vue-loader will remove its pitcher loader.
65
+ /[\\/]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) || '')) {
66
+ const seen = new Set();
67
+ const loaders = [];
68
+ // deduplicate loaders
69
+ for (const loader of loaderContext.loaders || []){
70
+ const identifier = 'string' == typeof loader ? loader : loader.path + loader.query;
71
+ if (!seen.has(identifier)) {
72
+ seen.add(identifier);
73
+ loaders.push(loader);
74
+ }
75
+ }
76
+ loaderContext.loaders = loaders;
77
+ }
78
+ });
79
+ });
103
80
  }
104
- if (!Object.keys(extraGroups).length) {
105
- return;
81
+ constructor(){
82
+ _define_property(this, "name", 'VueLoader15PitchFixPlugin');
106
83
  }
107
- chain.optimization.splitChunks({
108
- ...currentConfig,
109
- cacheGroups: {
110
- ...currentConfig.cacheGroups,
111
- ...extraGroups
112
- }
84
+ }
85
+ const isPlainObject = (obj)=>null !== obj && 'object' == typeof obj && '[object Object]' === Object.prototype.toString.call(obj);
86
+ const applySplitChunksRule = (api, options = {
87
+ vue: true,
88
+ router: true
89
+ })=>{
90
+ api.modifyBundlerChain((chain, { environment })=>{
91
+ const { config } = environment;
92
+ if ('split-by-experience' !== config.performance.chunkSplit.strategy) return;
93
+ const currentConfig = chain.optimization.splitChunks.values();
94
+ if (!isPlainObject(currentConfig)) return;
95
+ const extraGroups = {};
96
+ if (options.router) extraGroups.vue = {
97
+ name: 'lib-vue',
98
+ test: /node_modules[\\/](?:vue|vue-loader)[\\/]/,
99
+ priority: 0
100
+ };
101
+ if (options.router) extraGroups.router = {
102
+ name: 'lib-router',
103
+ test: /node_modules[\\/]vue-router[\\/]/,
104
+ priority: 0
105
+ };
106
+ if (!Object.keys(extraGroups).length) return;
107
+ chain.optimization.splitChunks({
108
+ ...currentConfig,
109
+ cacheGroups: {
110
+ ...currentConfig.cacheGroups,
111
+ ...extraGroups
112
+ }
113
+ });
113
114
  });
114
- });
115
115
  };
116
-
117
- // src/index.ts
118
- var require2 = (0, import_node_module.createRequire)(importMetaUrl);
119
- var PLUGIN_VUE2_NAME = "rsbuild:vue2";
116
+ const src_require = (0, external_node_module_namespaceObject.createRequire)(/*#__PURE__*/ function() {
117
+ return 'undefined' == typeof document ? new (module.require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
118
+ }());
119
+ const PLUGIN_VUE2_NAME = 'rsbuild:vue2';
120
120
  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");
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, { mergeEnvironmentConfig })=>{
127
+ // Support `<style module>` in Vue SFC
128
+ if (true === config.output.cssModules.auto) config.output.cssModules.auto = (path, query)=>{
129
+ if (VUE_REGEXP.test(path)) return query.includes('type=style') && query.includes('module=true');
130
+ return CSS_MODULES_REGEX.test(path);
131
+ };
132
+ const extraConfig = {
133
+ source: {
134
+ // should transpile all scripts from Vue SFC
135
+ include: [
136
+ /\.vue/
137
+ ]
138
+ }
139
+ };
140
+ return mergeEnvironmentConfig(config, extraConfig);
141
+ });
142
+ api.modifyBundlerChain((chain, { CHAIN_ID })=>{
143
+ chain.resolve.extensions.add('.vue');
144
+ // https://github.com/web-infra-dev/rsbuild/issues/1132
145
+ if (!chain.resolve.alias.get('vue$')) chain.resolve.alias.set('vue$', 'vue/dist/vue.runtime.esm.js');
146
+ const userLoaderOptions = options.vueLoaderOptions ?? {};
147
+ const compilerOptions = {
148
+ // https://github.com/vuejs/vue-cli/pull/3853
149
+ whitespace: 'condense',
150
+ ...userLoaderOptions.compilerOptions
151
+ };
152
+ const vueLoaderOptions = {
153
+ experimentalInlineMatchResource: true,
154
+ ...userLoaderOptions,
155
+ compilerOptions
156
+ };
157
+ const rule = chain.module.rule(CHAIN_ID.RULE.VUE);
158
+ rule.test(VUE_REGEXP).use(CHAIN_ID.USE.VUE).loader(src_require.resolve('vue-loader')).options(vueLoaderOptions);
159
+ if (chain.module.rules.has(CHAIN_ID.RULE.JS)) applyResolveConfig(rule, chain.module.rule(CHAIN_ID.RULE.JS));
160
+ // Support for lang="postcss" and lang="pcss" in SFC
161
+ chain.module.rule(CHAIN_ID.RULE.CSS).test(/\.(?:css|postcss|pcss)$/);
162
+ chain.plugin(CHAIN_ID.PLUGIN.VUE_LOADER_PLUGIN).use(external_vue_loader_namespaceObject.VueLoaderPlugin);
163
+ // we could remove this once a new vue-loader@15 is released with https://github.com/vuejs/vue-loader/pull/2071 shipped
164
+ chain.plugin('vue-loader-15-pitch-fix').use(VueLoader15PitchFixPlugin);
165
+ });
166
+ applySplitChunksRule(api, options.splitChunks);
141
167
  }
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
- };
168
+ };
165
169
  }
166
170
  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
- }
171
+ const fullySpecified = jsRule.resolve.get('fullySpecified');
172
+ const aliases = jsRule.resolve.alias.entries();
173
+ if (aliases) vueRule.resolve.alias.merge(aliases);
174
+ if (void 0 !== fullySpecified) vueRule.resolve.fullySpecified(fullySpecified);
175
175
  }
176
- // Annotate the CommonJS export names for ESM import in node:
177
- 0 && (module.exports = {
178
- PLUGIN_VUE2_NAME,
179
- pluginVue2
176
+ var __webpack_export_target__ = exports;
177
+ for(var i in __webpack_exports__)__webpack_export_target__[i] = __webpack_exports__[i];
178
+ if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
179
+ value: true
180
180
  });
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,136 @@
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__ from "node:module";
2
+ import * as __WEBPACK_EXTERNAL_MODULE_vue_loader__ 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
+ /**
14
+ * this plugin is a quick fix for issue https://github.com/web-infra-dev/rsbuild/issues/2093
15
+ */ class VueLoader15PitchFixPlugin {
16
+ apply(compiler) {
17
+ const { NormalModule } = compiler.webpack;
18
+ compiler.hooks.compilation.tap(this.name, (compilation)=>{
19
+ var _compilation_compiler_options_experiments, _compilation_compiler_options;
20
+ 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;
21
+ // the related issue only happens when experiments.css is on
22
+ if (!isExpCssOn) return;
23
+ NormalModule.getCompilationHooks(compilation).loader.tap(this.name, (loaderContext)=>{
24
+ var _loaderContext_loaders_, _loaderContext_loaders;
25
+ if (/[?&]type=style/.test(loaderContext.resourceQuery) && // the fix should be applied before `pitch` phase completed.
26
+ // once `pitch` phase completed, vue-loader will remove its pitcher loader.
27
+ /[\\/]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) || '')) {
28
+ const seen = new Set();
29
+ const loaders = [];
30
+ // deduplicate loaders
31
+ for (const loader of loaderContext.loaders || []){
32
+ const identifier = 'string' == typeof loader ? loader : loader.path + loader.query;
33
+ if (!seen.has(identifier)) {
34
+ seen.add(identifier);
35
+ loaders.push(loader);
36
+ }
37
+ }
38
+ loaderContext.loaders = loaders;
39
+ }
40
+ });
41
+ });
72
42
  }
73
- if (!Object.keys(extraGroups).length) {
74
- return;
43
+ constructor(){
44
+ _define_property(this, "name", 'VueLoader15PitchFixPlugin');
75
45
  }
76
- chain.optimization.splitChunks({
77
- ...currentConfig,
78
- cacheGroups: {
79
- ...currentConfig.cacheGroups,
80
- ...extraGroups
81
- }
46
+ }
47
+ const isPlainObject = (obj)=>null !== obj && 'object' == typeof obj && '[object Object]' === Object.prototype.toString.call(obj);
48
+ const applySplitChunksRule = (api, options = {
49
+ vue: true,
50
+ router: true
51
+ })=>{
52
+ api.modifyBundlerChain((chain, { environment })=>{
53
+ const { config } = environment;
54
+ if ('split-by-experience' !== config.performance.chunkSplit.strategy) return;
55
+ const currentConfig = chain.optimization.splitChunks.values();
56
+ if (!isPlainObject(currentConfig)) return;
57
+ const extraGroups = {};
58
+ if (options.router) extraGroups.vue = {
59
+ name: 'lib-vue',
60
+ test: /node_modules[\\/](?:vue|vue-loader)[\\/]/,
61
+ priority: 0
62
+ };
63
+ if (options.router) extraGroups.router = {
64
+ name: 'lib-router',
65
+ test: /node_modules[\\/]vue-router[\\/]/,
66
+ priority: 0
67
+ };
68
+ if (!Object.keys(extraGroups).length) return;
69
+ chain.optimization.splitChunks({
70
+ ...currentConfig,
71
+ cacheGroups: {
72
+ ...currentConfig.cacheGroups,
73
+ ...extraGroups
74
+ }
75
+ });
82
76
  });
83
- });
84
77
  };
85
-
86
- // src/index.ts
87
- var require2 = createRequire(import.meta.url);
88
- var PLUGIN_VUE2_NAME = "rsbuild:vue2";
78
+ const src_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module__.createRequire)(import.meta.url);
79
+ const PLUGIN_VUE2_NAME = 'rsbuild:vue2';
89
80
  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
- };
81
+ return {
82
+ name: PLUGIN_VUE2_NAME,
83
+ setup (api) {
84
+ const VUE_REGEXP = /\.vue$/;
85
+ const CSS_MODULES_REGEX = /\.modules?\.\w+$/i;
86
+ api.modifyEnvironmentConfig((config, { mergeEnvironmentConfig })=>{
87
+ // Support `<style module>` in Vue SFC
88
+ if (true === config.output.cssModules.auto) config.output.cssModules.auto = (path, query)=>{
89
+ if (VUE_REGEXP.test(path)) return query.includes('type=style') && query.includes('module=true');
90
+ return CSS_MODULES_REGEX.test(path);
91
+ };
92
+ const extraConfig = {
93
+ source: {
94
+ // should transpile all scripts from Vue SFC
95
+ include: [
96
+ /\.vue/
97
+ ]
98
+ }
99
+ };
100
+ return mergeEnvironmentConfig(config, extraConfig);
101
+ });
102
+ api.modifyBundlerChain((chain, { CHAIN_ID })=>{
103
+ chain.resolve.extensions.add('.vue');
104
+ // https://github.com/web-infra-dev/rsbuild/issues/1132
105
+ if (!chain.resolve.alias.get('vue$')) chain.resolve.alias.set('vue$', 'vue/dist/vue.runtime.esm.js');
106
+ const userLoaderOptions = options.vueLoaderOptions ?? {};
107
+ const compilerOptions = {
108
+ // https://github.com/vuejs/vue-cli/pull/3853
109
+ whitespace: 'condense',
110
+ ...userLoaderOptions.compilerOptions
111
+ };
112
+ const vueLoaderOptions = {
113
+ experimentalInlineMatchResource: true,
114
+ ...userLoaderOptions,
115
+ compilerOptions
116
+ };
117
+ const rule = chain.module.rule(CHAIN_ID.RULE.VUE);
118
+ rule.test(VUE_REGEXP).use(CHAIN_ID.USE.VUE).loader(src_require.resolve('vue-loader')).options(vueLoaderOptions);
119
+ if (chain.module.rules.has(CHAIN_ID.RULE.JS)) applyResolveConfig(rule, chain.module.rule(CHAIN_ID.RULE.JS));
120
+ // Support for lang="postcss" and lang="pcss" in SFC
121
+ chain.module.rule(CHAIN_ID.RULE.CSS).test(/\.(?:css|postcss|pcss)$/);
122
+ chain.plugin(CHAIN_ID.PLUGIN.VUE_LOADER_PLUGIN).use(__WEBPACK_EXTERNAL_MODULE_vue_loader__.VueLoaderPlugin);
123
+ // we could remove this once a new vue-loader@15 is released with https://github.com/vuejs/vue-loader/pull/2071 shipped
124
+ chain.plugin('vue-loader-15-pitch-fix').use(VueLoader15PitchFixPlugin);
125
+ });
126
+ applySplitChunksRule(api, options.splitChunks);
103
127
  }
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
- };
128
+ };
134
129
  }
135
130
  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
- }
131
+ const fullySpecified = jsRule.resolve.get('fullySpecified');
132
+ const aliases = jsRule.resolve.alias.entries();
133
+ if (aliases) vueRule.resolve.alias.merge(aliases);
134
+ if (void 0 !== fullySpecified) vueRule.resolve.fullySpecified(fullySpecified);
144
135
  }
145
- export {
146
- PLUGIN_VUE2_NAME,
147
- pluginVue2
148
- };
136
+ 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.2",
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,34 @@
27
36
  },
28
37
  "dependencies": {
29
38
  "vue-loader": "^15.11.1",
30
- "webpack": "^5.93.0"
39
+ "webpack": "^5.96.1"
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.48.2",
44
+ "@rsbuild/core": "^1.1.0",
45
+ "@rsbuild/plugin-less": "1.1.0",
46
+ "@rslib/core": "^0.0.18",
47
+ "@types/node": "^20.17.6",
38
48
  "nano-staged": "^0.8.0",
39
- "playwright": "^1.45.3",
49
+ "playwright": "^1.48.2",
40
50
  "simple-git-hooks": "^2.11.1",
41
- "tsup": "^8.2.3",
42
- "typescript": "^5.5.4",
43
- "vue": "^2.7.14"
51
+ "tsup": "^8.3.5",
52
+ "typescript": "^5.6.3",
53
+ "vue": "^2.7.16"
44
54
  },
45
55
  "peerDependencies": {
46
- "@rsbuild/core": "1.x || ^1.0.1-beta.0"
56
+ "@rsbuild/core": "1.x"
47
57
  },
48
58
  "peerDependenciesMeta": {
49
59
  "@rsbuild/core": {
50
60
  "optional": true
51
61
  }
52
62
  },
63
+ "packageManager": "pnpm@9.12.3",
53
64
  "publishConfig": {
54
65
  "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"
66
+ "registry": "https://registry.npmjs.org/",
67
+ "provenance": true
63
68
  }
64
- }
69
+ }
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 };