@rsbuild/plugin-vue2 0.0.0-next-20240528072128 → 0.0.0-next-20240723074951

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
@@ -35,6 +35,7 @@ var __publicField = (obj, key, value) => {
35
35
  // src/index.ts
36
36
  var src_exports = {};
37
37
  __export(src_exports, {
38
+ PLUGIN_VUE2_NAME: () => PLUGIN_VUE2_NAME,
38
39
  pluginVue2: () => pluginVue2
39
40
  });
40
41
  module.exports = __toCommonJS(src_exports);
@@ -80,52 +81,59 @@ var VueLoader15PitchFixPlugin = class {
80
81
  };
81
82
 
82
83
  // src/splitChunks.ts
83
- var import_shared = require("@rsbuild/shared");
84
+ var isPlainObject = (obj) => obj !== null && typeof obj === "object" && Object.prototype.toString.call(obj) === "[object Object]";
84
85
  var applySplitChunksRule = (api, options = {
85
86
  vue: true,
86
87
  router: true
87
88
  }) => {
88
- api.modifyBundlerChain((chain) => {
89
- const config = api.getNormalizedConfig();
89
+ api.modifyBundlerChain((chain, { environment }) => {
90
+ const { config } = environment;
90
91
  if (config.performance.chunkSplit.strategy !== "split-by-experience") {
91
92
  return;
92
93
  }
93
94
  const currentConfig = chain.optimization.splitChunks.values();
94
- if (!(0, import_shared.isPlainObject)(currentConfig)) {
95
+ if (!isPlainObject(currentConfig)) {
95
96
  return;
96
97
  }
97
98
  const extraGroups = {};
98
- if (options.vue) {
99
- extraGroups.vue = ["vue", "vue-loader"];
99
+ if (options.router) {
100
+ extraGroups.vue = {
101
+ name: "lib-vue",
102
+ test: /node_modules[\\/](?:vue|vue-loader)[\\/]/,
103
+ priority: 0
104
+ };
100
105
  }
101
106
  if (options.router) {
102
- extraGroups.router = ["vue-router"];
107
+ extraGroups.router = {
108
+ name: "lib-router",
109
+ test: /node_modules[\\/]vue-router[\\/]/,
110
+ priority: 0
111
+ };
103
112
  }
104
113
  if (!Object.keys(extraGroups).length) {
105
114
  return;
106
115
  }
107
116
  chain.optimization.splitChunks({
108
117
  ...currentConfig,
109
- // @ts-expect-error Rspack and Webpack uses different cacheGroups type
110
118
  cacheGroups: {
111
119
  ...currentConfig.cacheGroups,
112
- ...(0, import_shared.createCacheGroups)(extraGroups)
120
+ ...extraGroups
113
121
  }
114
122
  });
115
123
  });
116
124
  };
117
125
 
118
126
  // src/index.ts
127
+ var PLUGIN_VUE2_NAME = "rsbuild:vue2";
119
128
  function pluginVue2(options = {}) {
120
129
  return {
121
- name: "rsbuild:vue2",
130
+ name: PLUGIN_VUE2_NAME,
122
131
  setup(api) {
123
132
  const VUE_REGEXP = /\.vue$/;
124
133
  const CSS_MODULES_REGEX = /\.modules?\.\w+$/i;
125
134
  api.modifyRsbuildConfig((config) => {
126
- var _a;
127
- config.output || (config.output = {});
128
- (_a = config.output).cssModules || (_a.cssModules = {});
135
+ config.output ||= {};
136
+ config.output.cssModules ||= {};
129
137
  if (config.output.cssModules.auto === true) {
130
138
  config.output.cssModules.auto = (path, query) => {
131
139
  if (VUE_REGEXP.test(path)) {
@@ -143,7 +151,8 @@ function pluginVue2(options = {}) {
143
151
  }
144
152
  const userLoaderOptions = options.vueLoaderOptions ?? {};
145
153
  const compilerOptions = {
146
- preserveWhitespace: false,
154
+ // https://github.com/vuejs/vue-cli/pull/3853
155
+ whitespace: "condense",
147
156
  ...userLoaderOptions.compilerOptions
148
157
  };
149
158
  const vueLoaderOptions = {
@@ -151,16 +160,31 @@ function pluginVue2(options = {}) {
151
160
  ...userLoaderOptions,
152
161
  compilerOptions
153
162
  };
154
- chain.module.rule(CHAIN_ID.RULE.VUE).test(VUE_REGEXP).use(CHAIN_ID.USE.VUE).loader(require.resolve("vue-loader")).options(vueLoaderOptions);
163
+ const rule = chain.module.rule(CHAIN_ID.RULE.VUE);
164
+ rule.test(VUE_REGEXP).use(CHAIN_ID.USE.VUE).loader(require.resolve("vue-loader")).options(vueLoaderOptions);
165
+ if (chain.module.rules.has(CHAIN_ID.RULE.JS)) {
166
+ applyResolveConfig(rule, chain.module.rule(CHAIN_ID.RULE.JS));
167
+ }
155
168
  chain.module.rule(CHAIN_ID.RULE.CSS).test(/\.(?:css|postcss|pcss)$/);
156
169
  chain.plugin(CHAIN_ID.PLUGIN.VUE_LOADER_PLUGIN).use(import_vue_loader.VueLoaderPlugin);
157
- chain.plugin(CHAIN_ID.PLUGIN.VUE_LOADER_15_PITCH_FIX_PLUGIN).use(VueLoader15PitchFixPlugin);
170
+ chain.plugin("vue-loader-15-pitch-fix").use(VueLoader15PitchFixPlugin);
158
171
  });
159
172
  applySplitChunksRule(api, options.splitChunks);
160
173
  }
161
174
  };
162
175
  }
176
+ function applyResolveConfig(vueRule, jsRule) {
177
+ const fullySpecified = jsRule.resolve.get("fullySpecified");
178
+ const aliases = jsRule.resolve.alias.entries();
179
+ if (aliases) {
180
+ vueRule.resolve.alias.merge(aliases);
181
+ }
182
+ if (fullySpecified !== void 0) {
183
+ vueRule.resolve.fullySpecified(fullySpecified);
184
+ }
185
+ }
163
186
  // Annotate the CommonJS export names for ESM import in node:
164
187
  0 && (module.exports = {
188
+ PLUGIN_VUE2_NAME,
165
189
  pluginVue2
166
190
  });
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,6 +23,5 @@ type PluginVueOptions = {
24
23
  */
25
24
  splitChunks?: SplitVueChunkOptions;
26
25
  };
27
- declare function pluginVue2(options?: PluginVueOptions): RsbuildPlugin;
28
-
29
- export { 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
@@ -15,7 +15,7 @@ var __publicField = (obj, key, value) => {
15
15
  return value;
16
16
  };
17
17
 
18
- // ../../node_modules/.pnpm/@modern-js+module-tools@2.50.0_eslint@9.3.0_typescript@5.4.5/node_modules/@modern-js/module-tools/shims/esm.js
18
+ // ../../node_modules/.pnpm/@modern-js+module-tools@2.56.0_typescript@5.5.2/node_modules/@modern-js/module-tools/shims/esm.js
19
19
  import { fileURLToPath } from "url";
20
20
  import path from "path";
21
21
 
@@ -62,13 +62,13 @@ var VueLoader15PitchFixPlugin = class {
62
62
  };
63
63
 
64
64
  // src/splitChunks.ts
65
- import { createCacheGroups, isPlainObject } from "@rsbuild/shared";
65
+ var isPlainObject = (obj) => obj !== null && typeof obj === "object" && Object.prototype.toString.call(obj) === "[object Object]";
66
66
  var applySplitChunksRule = (api, options = {
67
67
  vue: true,
68
68
  router: true
69
69
  }) => {
70
- api.modifyBundlerChain((chain) => {
71
- const config = api.getNormalizedConfig();
70
+ api.modifyBundlerChain((chain, { environment }) => {
71
+ const { config } = environment;
72
72
  if (config.performance.chunkSplit.strategy !== "split-by-experience") {
73
73
  return;
74
74
  }
@@ -77,37 +77,44 @@ var applySplitChunksRule = (api, options = {
77
77
  return;
78
78
  }
79
79
  const extraGroups = {};
80
- if (options.vue) {
81
- extraGroups.vue = ["vue", "vue-loader"];
80
+ if (options.router) {
81
+ extraGroups.vue = {
82
+ name: "lib-vue",
83
+ test: /node_modules[\\/](?:vue|vue-loader)[\\/]/,
84
+ priority: 0
85
+ };
82
86
  }
83
87
  if (options.router) {
84
- extraGroups.router = ["vue-router"];
88
+ extraGroups.router = {
89
+ name: "lib-router",
90
+ test: /node_modules[\\/]vue-router[\\/]/,
91
+ priority: 0
92
+ };
85
93
  }
86
94
  if (!Object.keys(extraGroups).length) {
87
95
  return;
88
96
  }
89
97
  chain.optimization.splitChunks({
90
98
  ...currentConfig,
91
- // @ts-expect-error Rspack and Webpack uses different cacheGroups type
92
99
  cacheGroups: {
93
100
  ...currentConfig.cacheGroups,
94
- ...createCacheGroups(extraGroups)
101
+ ...extraGroups
95
102
  }
96
103
  });
97
104
  });
98
105
  };
99
106
 
100
107
  // src/index.ts
108
+ var PLUGIN_VUE2_NAME = "rsbuild:vue2";
101
109
  function pluginVue2(options = {}) {
102
110
  return {
103
- name: "rsbuild:vue2",
111
+ name: PLUGIN_VUE2_NAME,
104
112
  setup(api) {
105
113
  const VUE_REGEXP = /\.vue$/;
106
114
  const CSS_MODULES_REGEX = /\.modules?\.\w+$/i;
107
115
  api.modifyRsbuildConfig((config) => {
108
- var _a;
109
- config.output || (config.output = {});
110
- (_a = config.output).cssModules || (_a.cssModules = {});
116
+ config.output ||= {};
117
+ config.output.cssModules ||= {};
111
118
  if (config.output.cssModules.auto === true) {
112
119
  config.output.cssModules.auto = (path2, query) => {
113
120
  if (VUE_REGEXP.test(path2)) {
@@ -125,7 +132,8 @@ function pluginVue2(options = {}) {
125
132
  }
126
133
  const userLoaderOptions = options.vueLoaderOptions ?? {};
127
134
  const compilerOptions = {
128
- preserveWhitespace: false,
135
+ // https://github.com/vuejs/vue-cli/pull/3853
136
+ whitespace: "condense",
129
137
  ...userLoaderOptions.compilerOptions
130
138
  };
131
139
  const vueLoaderOptions = {
@@ -133,15 +141,30 @@ function pluginVue2(options = {}) {
133
141
  ...userLoaderOptions,
134
142
  compilerOptions
135
143
  };
136
- chain.module.rule(CHAIN_ID.RULE.VUE).test(VUE_REGEXP).use(CHAIN_ID.USE.VUE).loader(__require.resolve("vue-loader")).options(vueLoaderOptions);
144
+ const rule = chain.module.rule(CHAIN_ID.RULE.VUE);
145
+ rule.test(VUE_REGEXP).use(CHAIN_ID.USE.VUE).loader(__require.resolve("vue-loader")).options(vueLoaderOptions);
146
+ if (chain.module.rules.has(CHAIN_ID.RULE.JS)) {
147
+ applyResolveConfig(rule, chain.module.rule(CHAIN_ID.RULE.JS));
148
+ }
137
149
  chain.module.rule(CHAIN_ID.RULE.CSS).test(/\.(?:css|postcss|pcss)$/);
138
150
  chain.plugin(CHAIN_ID.PLUGIN.VUE_LOADER_PLUGIN).use(VueLoaderPlugin);
139
- chain.plugin(CHAIN_ID.PLUGIN.VUE_LOADER_15_PITCH_FIX_PLUGIN).use(VueLoader15PitchFixPlugin);
151
+ chain.plugin("vue-loader-15-pitch-fix").use(VueLoader15PitchFixPlugin);
140
152
  });
141
153
  applySplitChunksRule(api, options.splitChunks);
142
154
  }
143
155
  };
144
156
  }
157
+ function applyResolveConfig(vueRule, jsRule) {
158
+ const fullySpecified = jsRule.resolve.get("fullySpecified");
159
+ const aliases = jsRule.resolve.alias.entries();
160
+ if (aliases) {
161
+ vueRule.resolve.alias.merge(aliases);
162
+ }
163
+ if (fullySpecified !== void 0) {
164
+ vueRule.resolve.fullySpecified(fullySpecified);
165
+ }
166
+ }
145
167
  export {
168
+ PLUGIN_VUE2_NAME,
146
169
  pluginVue2
147
170
  };
@@ -0,0 +1,3 @@
1
+ import type { RsbuildPluginAPI } from '@rsbuild/core';
2
+ import type { SplitVueChunkOptions } from '.';
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": "0.0.0-next-20240528072128",
3
+ "version": "0.0.0-next-20240723074951",
4
4
  "description": "Vue 2 plugin of Rsbuild",
5
5
  "homepage": "https://rsbuild.dev",
6
6
  "repository": {
@@ -24,17 +24,16 @@
24
24
  ],
25
25
  "dependencies": {
26
26
  "vue-loader": "^15.11.1",
27
- "webpack": "^5.91.0",
28
- "@rsbuild/shared": "0.0.0-next-20240528072128"
27
+ "webpack": "^5.93.0"
29
28
  },
30
29
  "devDependencies": {
31
- "typescript": "^5.4.2",
32
- "webpack": "^5.91.0",
33
- "@rsbuild/core": "0.0.0-next-20240528072128",
34
- "@scripts/test-helper": "0.0.0-next-20240528072128"
30
+ "typescript": "^5.5.2",
31
+ "webpack": "^5.93.0",
32
+ "@rsbuild/core": "0.0.0-next-20240723074951",
33
+ "@scripts/test-helper": "0.0.0-next-20240723074951"
35
34
  },
36
35
  "peerDependencies": {
37
- "@rsbuild/core": "0.0.0-next-20240528072128"
36
+ "@rsbuild/core": "0.0.0-next-20240723074951"
38
37
  },
39
38
  "publishConfig": {
40
39
  "access": "public",