@rsbuild/plugin-vue2 0.0.0-next-20240514150515 → 0.0.0-next-20240708070719

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.
@@ -1,4 +1,4 @@
1
- import type { Rspack } from '@rsbuild/shared';
1
+ import type { Rspack } from '@rsbuild/core';
2
2
  /**
3
3
  * this plugin is a quick fix for issue https://github.com/web-infra-dev/rsbuild/issues/2093
4
4
  */
package/dist/index.cjs CHANGED
@@ -35,10 +35,10 @@ 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);
41
- var import_shared2 = require("@rsbuild/shared");
42
42
  var import_vue_loader = require("vue-loader");
43
43
 
44
44
  // src/VueLoader15PitchFixPlugin.ts
@@ -81,69 +81,110 @@ var VueLoader15PitchFixPlugin = class {
81
81
  };
82
82
 
83
83
  // src/splitChunks.ts
84
- var import_shared = require("@rsbuild/shared");
84
+ var isPlainObject = (obj) => obj !== null && typeof obj === "object" && Object.prototype.toString.call(obj) === "[object Object]";
85
85
  var applySplitChunksRule = (api, options = {
86
86
  vue: true,
87
87
  router: true
88
88
  }) => {
89
- api.modifyBundlerChain((chain) => {
90
- const config = api.getNormalizedConfig();
89
+ api.modifyBundlerChain((chain, { environment }) => {
90
+ const { config } = environment;
91
91
  if (config.performance.chunkSplit.strategy !== "split-by-experience") {
92
92
  return;
93
93
  }
94
94
  const currentConfig = chain.optimization.splitChunks.values();
95
- if (!(0, import_shared.isPlainObject)(currentConfig)) {
95
+ if (!isPlainObject(currentConfig)) {
96
96
  return;
97
97
  }
98
98
  const extraGroups = {};
99
- if (options.vue) {
100
- 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
+ };
101
105
  }
102
106
  if (options.router) {
103
- extraGroups.router = ["vue-router"];
107
+ extraGroups.router = {
108
+ name: "lib-router",
109
+ test: /node_modules[\\/]vue-router[\\/]/,
110
+ priority: 0
111
+ };
104
112
  }
105
113
  if (!Object.keys(extraGroups).length) {
106
114
  return;
107
115
  }
108
116
  chain.optimization.splitChunks({
109
117
  ...currentConfig,
110
- // @ts-expect-error Rspack and Webpack uses different cacheGroups type
111
118
  cacheGroups: {
112
119
  ...currentConfig.cacheGroups,
113
- ...(0, import_shared.createCacheGroups)(extraGroups)
120
+ ...extraGroups
114
121
  }
115
122
  });
116
123
  });
117
124
  };
118
125
 
119
126
  // src/index.ts
127
+ var PLUGIN_VUE2_NAME = "rsbuild:vue2";
120
128
  function pluginVue2(options = {}) {
121
129
  return {
122
- name: "rsbuild:vue2",
130
+ name: PLUGIN_VUE2_NAME,
123
131
  setup(api) {
132
+ const VUE_REGEXP = /\.vue$/;
133
+ const CSS_MODULES_REGEX = /\.modules?\.\w+$/i;
134
+ api.modifyRsbuildConfig((config) => {
135
+ config.output ||= {};
136
+ config.output.cssModules ||= {};
137
+ if (config.output.cssModules.auto === true) {
138
+ config.output.cssModules.auto = (path, query) => {
139
+ if (VUE_REGEXP.test(path)) {
140
+ return query.includes("type=style") && query.includes("module=true");
141
+ }
142
+ return CSS_MODULES_REGEX.test(path);
143
+ };
144
+ }
145
+ return config;
146
+ });
124
147
  api.modifyBundlerChain((chain, { CHAIN_ID }) => {
125
148
  chain.resolve.extensions.add(".vue");
126
149
  if (!chain.resolve.alias.get("vue$")) {
127
150
  chain.resolve.alias.set("vue$", "vue/dist/vue.runtime.esm.js");
128
151
  }
129
- const vueLoaderOptions = (0, import_shared2.deepmerge)(
130
- {
131
- compilerOptions: {
132
- preserveWhitespace: false
133
- },
134
- experimentalInlineMatchResource: true
135
- },
136
- options.vueLoaderOptions ?? {}
137
- );
138
- chain.module.rule(CHAIN_ID.RULE.VUE).test(/\.vue$/).use(CHAIN_ID.USE.VUE).loader(require.resolve("vue-loader")).options(vueLoaderOptions);
152
+ const userLoaderOptions = options.vueLoaderOptions ?? {};
153
+ const compilerOptions = {
154
+ // https://github.com/vuejs/vue-cli/pull/3853
155
+ whitespace: "condense",
156
+ ...userLoaderOptions.compilerOptions
157
+ };
158
+ const vueLoaderOptions = {
159
+ experimentalInlineMatchResource: true,
160
+ ...userLoaderOptions,
161
+ compilerOptions
162
+ };
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
+ }
168
+ chain.module.rule(CHAIN_ID.RULE.CSS).test(/\.(?:css|postcss|pcss)$/);
139
169
  chain.plugin(CHAIN_ID.PLUGIN.VUE_LOADER_PLUGIN).use(import_vue_loader.VueLoaderPlugin);
140
- chain.plugin(CHAIN_ID.PLUGIN.VUE_LOADER_15_PITCH_FIX_PLUGIN).use(VueLoader15PitchFixPlugin);
170
+ chain.plugin("vue-loader-15-pitch-fix").use(VueLoader15PitchFixPlugin);
141
171
  });
142
172
  applySplitChunksRule(api, options.splitChunks);
143
173
  }
144
174
  };
145
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
+ }
146
186
  // Annotate the CommonJS export names for ESM import in node:
147
187
  0 && (module.exports = {
188
+ PLUGIN_VUE2_NAME,
148
189
  pluginVue2
149
190
  });
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { RsbuildPlugin } from '@rsbuild/core';
2
- import type { VueLoaderOptions } from 'vue-loader';
2
+ import { type VueLoaderOptions } from 'vue-loader';
3
3
  export type SplitVueChunkOptions = {
4
4
  /**
5
5
  * Whether to enable split chunking for Vue-related dependencies (e.g., vue, vue-loader).
@@ -23,4 +23,5 @@ export type PluginVueOptions = {
23
23
  */
24
24
  splitChunks?: SplitVueChunkOptions;
25
25
  };
26
+ export declare const PLUGIN_VUE2_NAME = "rsbuild:vue2";
26
27
  export declare function pluginVue2(options?: PluginVueOptions): RsbuildPlugin;
package/dist/index.js CHANGED
@@ -15,12 +15,11 @@ var __publicField = (obj, key, value) => {
15
15
  return value;
16
16
  };
17
17
 
18
- // ../../node_modules/.pnpm/@modern-js+module-tools@2.49.3_eslint@8.57.0_typescript@5.4.5/node_modules/@modern-js/module-tools/shims/esm.js
18
+ // ../../node_modules/.pnpm/@modern-js+module-tools@2.54.6_eslint@9.6.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
 
22
22
  // src/index.ts
23
- import { deepmerge } from "@rsbuild/shared";
24
23
  import { VueLoaderPlugin } from "vue-loader";
25
24
 
26
25
  // src/VueLoader15PitchFixPlugin.ts
@@ -63,16 +62,13 @@ var VueLoader15PitchFixPlugin = class {
63
62
  };
64
63
 
65
64
  // src/splitChunks.ts
66
- import {
67
- createCacheGroups,
68
- isPlainObject
69
- } from "@rsbuild/shared";
65
+ var isPlainObject = (obj) => obj !== null && typeof obj === "object" && Object.prototype.toString.call(obj) === "[object Object]";
70
66
  var applySplitChunksRule = (api, options = {
71
67
  vue: true,
72
68
  router: true
73
69
  }) => {
74
- api.modifyBundlerChain((chain) => {
75
- const config = api.getNormalizedConfig();
70
+ api.modifyBundlerChain((chain, { environment }) => {
71
+ const { config } = environment;
76
72
  if (config.performance.chunkSplit.strategy !== "split-by-experience") {
77
73
  return;
78
74
  }
@@ -81,53 +77,94 @@ var applySplitChunksRule = (api, options = {
81
77
  return;
82
78
  }
83
79
  const extraGroups = {};
84
- if (options.vue) {
85
- 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
+ };
86
86
  }
87
87
  if (options.router) {
88
- extraGroups.router = ["vue-router"];
88
+ extraGroups.router = {
89
+ name: "lib-router",
90
+ test: /node_modules[\\/]vue-router[\\/]/,
91
+ priority: 0
92
+ };
89
93
  }
90
94
  if (!Object.keys(extraGroups).length) {
91
95
  return;
92
96
  }
93
97
  chain.optimization.splitChunks({
94
98
  ...currentConfig,
95
- // @ts-expect-error Rspack and Webpack uses different cacheGroups type
96
99
  cacheGroups: {
97
100
  ...currentConfig.cacheGroups,
98
- ...createCacheGroups(extraGroups)
101
+ ...extraGroups
99
102
  }
100
103
  });
101
104
  });
102
105
  };
103
106
 
104
107
  // src/index.ts
108
+ var PLUGIN_VUE2_NAME = "rsbuild:vue2";
105
109
  function pluginVue2(options = {}) {
106
110
  return {
107
- name: "rsbuild:vue2",
111
+ name: PLUGIN_VUE2_NAME,
108
112
  setup(api) {
113
+ const VUE_REGEXP = /\.vue$/;
114
+ const CSS_MODULES_REGEX = /\.modules?\.\w+$/i;
115
+ api.modifyRsbuildConfig((config) => {
116
+ config.output ||= {};
117
+ config.output.cssModules ||= {};
118
+ if (config.output.cssModules.auto === true) {
119
+ config.output.cssModules.auto = (path2, query) => {
120
+ if (VUE_REGEXP.test(path2)) {
121
+ return query.includes("type=style") && query.includes("module=true");
122
+ }
123
+ return CSS_MODULES_REGEX.test(path2);
124
+ };
125
+ }
126
+ return config;
127
+ });
109
128
  api.modifyBundlerChain((chain, { CHAIN_ID }) => {
110
129
  chain.resolve.extensions.add(".vue");
111
130
  if (!chain.resolve.alias.get("vue$")) {
112
131
  chain.resolve.alias.set("vue$", "vue/dist/vue.runtime.esm.js");
113
132
  }
114
- const vueLoaderOptions = deepmerge(
115
- {
116
- compilerOptions: {
117
- preserveWhitespace: false
118
- },
119
- experimentalInlineMatchResource: true
120
- },
121
- options.vueLoaderOptions ?? {}
122
- );
123
- chain.module.rule(CHAIN_ID.RULE.VUE).test(/\.vue$/).use(CHAIN_ID.USE.VUE).loader(__require.resolve("vue-loader")).options(vueLoaderOptions);
133
+ const userLoaderOptions = options.vueLoaderOptions ?? {};
134
+ const compilerOptions = {
135
+ // https://github.com/vuejs/vue-cli/pull/3853
136
+ whitespace: "condense",
137
+ ...userLoaderOptions.compilerOptions
138
+ };
139
+ const vueLoaderOptions = {
140
+ experimentalInlineMatchResource: true,
141
+ ...userLoaderOptions,
142
+ compilerOptions
143
+ };
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
+ }
149
+ chain.module.rule(CHAIN_ID.RULE.CSS).test(/\.(?:css|postcss|pcss)$/);
124
150
  chain.plugin(CHAIN_ID.PLUGIN.VUE_LOADER_PLUGIN).use(VueLoaderPlugin);
125
- chain.plugin(CHAIN_ID.PLUGIN.VUE_LOADER_15_PITCH_FIX_PLUGIN).use(VueLoader15PitchFixPlugin);
151
+ chain.plugin("vue-loader-15-pitch-fix").use(VueLoader15PitchFixPlugin);
126
152
  });
127
153
  applySplitChunksRule(api, options.splitChunks);
128
154
  }
129
155
  };
130
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
+ }
131
167
  export {
168
+ PLUGIN_VUE2_NAME,
132
169
  pluginVue2
133
170
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-vue2",
3
- "version": "0.0.0-next-20240514150515",
3
+ "version": "0.0.0-next-20240708070719",
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-20240514150515"
27
+ "webpack": "^5.92.1"
29
28
  },
30
29
  "devDependencies": {
31
- "typescript": "^5.4.2",
32
- "webpack": "^5.91.0",
33
- "@rsbuild/core": "0.0.0-next-20240514150515",
34
- "@scripts/test-helper": "0.0.0-next-20240514150515"
30
+ "typescript": "^5.5.2",
31
+ "webpack": "^5.92.1",
32
+ "@rsbuild/core": "0.0.0-next-20240708070719",
33
+ "@scripts/test-helper": "0.0.0-next-20240708070719"
35
34
  },
36
35
  "peerDependencies": {
37
- "@rsbuild/core": "0.0.0-next-20240514150515"
36
+ "@rsbuild/core": "0.0.0-next-20240708070719"
38
37
  },
39
38
  "publishConfig": {
40
39
  "access": "public",