@rsbuild/plugin-babel 0.3.11 → 0.4.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 CHANGED
@@ -89,7 +89,6 @@ declare const getDefaultBabelOptions: (decorators: Decorators) => {
89
89
  isTSX: boolean;
90
90
  })[][];
91
91
  };
92
-
93
92
  declare const pluginBabel: (options?: PluginBabelOptions) => RsbuildPlugin;
94
93
 
95
94
  declare const getBabelUtils: (config: TransformOptions) => BabelConfigUtils;
package/dist/index.js CHANGED
@@ -40,7 +40,6 @@ module.exports = __toCommonJS(src_exports);
40
40
 
41
41
  // src/plugin.ts
42
42
  var import_node_path2 = __toESM(require("path"));
43
- var import_core = require("@rsbuild/core");
44
43
  var import_shared2 = require("@rsbuild/shared");
45
44
 
46
45
  // src/helper.ts
@@ -174,6 +173,7 @@ var modifyBabelLoaderOptions = ({
174
173
  };
175
174
 
176
175
  // src/plugin.ts
176
+ var PLUGIN_BABEL_NAME = "rsbuild:babel";
177
177
  var DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS = {
178
178
  allowNamespaces: true,
179
179
  allExtensions: true,
@@ -201,43 +201,46 @@ var getDefaultBabelOptions = (decorators) => {
201
201
  };
202
202
  };
203
203
  var pluginBabel = (options = {}) => ({
204
- name: import_core.PLUGIN_BABEL_NAME,
204
+ name: PLUGIN_BABEL_NAME,
205
205
  setup(api) {
206
- api.modifyBundlerChain(async (chain, { CHAIN_ID }) => {
207
- const config = api.getNormalizedConfig();
208
- const getBabelOptions = () => {
209
- const baseConfig = getDefaultBabelOptions(config.source.decorators);
210
- const userBabelConfig = applyUserBabelConfig(
211
- (0, import_shared2.cloneDeep)(baseConfig),
212
- options.babelLoaderOptions
206
+ api.modifyBundlerChain({
207
+ order: "pre",
208
+ handler: async (chain, { CHAIN_ID }) => {
209
+ const config = api.getNormalizedConfig();
210
+ const getBabelOptions = () => {
211
+ const baseConfig = getDefaultBabelOptions(config.source.decorators);
212
+ const userBabelConfig = applyUserBabelConfig(
213
+ (0, import_shared2.cloneDeep)(baseConfig),
214
+ options.babelLoaderOptions
215
+ );
216
+ return userBabelConfig;
217
+ };
218
+ const babelOptions = getBabelOptions();
219
+ const babelLoader = import_node_path2.default.resolve(
220
+ __dirname,
221
+ "../compiled/babel-loader/index.js"
213
222
  );
214
- return userBabelConfig;
215
- };
216
- const babelOptions = getBabelOptions();
217
- const babelLoader = import_node_path2.default.resolve(
218
- __dirname,
219
- "../compiled/babel-loader/index.js"
220
- );
221
- const { include, exclude } = options;
222
- if (include || exclude) {
223
- const rule = chain.module.rule(BABEL_JS_RULE);
224
- if (include) {
225
- (0, import_shared2.castArray)(include).forEach((condition) => {
226
- rule.include.add(condition);
227
- });
228
- }
229
- if (exclude) {
230
- (0, import_shared2.castArray)(exclude).forEach((condition) => {
231
- rule.exclude.add(condition);
232
- });
223
+ const { include, exclude } = options;
224
+ if (include || exclude) {
225
+ const rule = chain.module.rule(BABEL_JS_RULE);
226
+ if (include) {
227
+ (0, import_shared2.castArray)(include).forEach((condition) => {
228
+ rule.include.add(condition);
229
+ });
230
+ }
231
+ if (exclude) {
232
+ (0, import_shared2.castArray)(exclude).forEach((condition) => {
233
+ rule.exclude.add(condition);
234
+ });
235
+ }
236
+ const swcRule = chain.module.rules.get(CHAIN_ID.RULE.JS).use(CHAIN_ID.USE.SWC);
237
+ const swcLoader = swcRule.get("loader");
238
+ const swcOptions = swcRule.get("options");
239
+ rule.test(import_shared2.SCRIPT_REGEX).use(CHAIN_ID.USE.SWC).loader(swcLoader).options(swcOptions).end().use(CHAIN_ID.USE.BABEL).loader(babelLoader).options(babelOptions);
240
+ } else {
241
+ const rule = chain.module.rule(CHAIN_ID.RULE.JS);
242
+ rule.test(import_shared2.SCRIPT_REGEX).use(CHAIN_ID.USE.BABEL).after(CHAIN_ID.USE.SWC).loader(babelLoader).options(babelOptions);
233
243
  }
234
- const swcRule = chain.module.rules.get(CHAIN_ID.RULE.JS).use(CHAIN_ID.USE.SWC);
235
- const swcLoader = swcRule.get("loader");
236
- const swcOptions = swcRule.get("options");
237
- rule.test(import_shared2.SCRIPT_REGEX).use(CHAIN_ID.USE.SWC).loader(swcLoader).options(swcOptions).end().use(CHAIN_ID.USE.BABEL).loader(babelLoader).options(babelOptions);
238
- } else {
239
- const rule = chain.module.rule(CHAIN_ID.RULE.JS);
240
- rule.test(import_shared2.SCRIPT_REGEX).use(CHAIN_ID.USE.BABEL).after(CHAIN_ID.USE.SWC).loader(babelLoader).options(babelOptions);
241
244
  }
242
245
  });
243
246
  }
package/dist/index.mjs CHANGED
@@ -18,12 +18,11 @@ var __dirname = /* @__PURE__ */ getDirname();
18
18
 
19
19
  // src/plugin.ts
20
20
  import path2 from "path";
21
- import { PLUGIN_BABEL_NAME } from "@rsbuild/core";
22
21
  import {
22
+ isProd,
23
23
  castArray as castArray2,
24
24
  cloneDeep,
25
- SCRIPT_REGEX,
26
- isProd
25
+ SCRIPT_REGEX
27
26
  } from "@rsbuild/shared";
28
27
 
29
28
  // src/helper.ts
@@ -160,6 +159,7 @@ var modifyBabelLoaderOptions = ({
160
159
  };
161
160
 
162
161
  // src/plugin.ts
162
+ var PLUGIN_BABEL_NAME = "rsbuild:babel";
163
163
  var DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS = {
164
164
  allowNamespaces: true,
165
165
  allExtensions: true,
@@ -189,41 +189,44 @@ var getDefaultBabelOptions = (decorators) => {
189
189
  var pluginBabel = (options = {}) => ({
190
190
  name: PLUGIN_BABEL_NAME,
191
191
  setup(api) {
192
- api.modifyBundlerChain(async (chain, { CHAIN_ID }) => {
193
- const config = api.getNormalizedConfig();
194
- const getBabelOptions = () => {
195
- const baseConfig = getDefaultBabelOptions(config.source.decorators);
196
- const userBabelConfig = applyUserBabelConfig(
197
- cloneDeep(baseConfig),
198
- options.babelLoaderOptions
192
+ api.modifyBundlerChain({
193
+ order: "pre",
194
+ handler: async (chain, { CHAIN_ID }) => {
195
+ const config = api.getNormalizedConfig();
196
+ const getBabelOptions = () => {
197
+ const baseConfig = getDefaultBabelOptions(config.source.decorators);
198
+ const userBabelConfig = applyUserBabelConfig(
199
+ cloneDeep(baseConfig),
200
+ options.babelLoaderOptions
201
+ );
202
+ return userBabelConfig;
203
+ };
204
+ const babelOptions = getBabelOptions();
205
+ const babelLoader = path2.resolve(
206
+ __dirname,
207
+ "../compiled/babel-loader/index.js"
199
208
  );
200
- return userBabelConfig;
201
- };
202
- const babelOptions = getBabelOptions();
203
- const babelLoader = path2.resolve(
204
- __dirname,
205
- "../compiled/babel-loader/index.js"
206
- );
207
- const { include, exclude } = options;
208
- if (include || exclude) {
209
- const rule = chain.module.rule(BABEL_JS_RULE);
210
- if (include) {
211
- castArray2(include).forEach((condition) => {
212
- rule.include.add(condition);
213
- });
214
- }
215
- if (exclude) {
216
- castArray2(exclude).forEach((condition) => {
217
- rule.exclude.add(condition);
218
- });
209
+ const { include, exclude } = options;
210
+ if (include || exclude) {
211
+ const rule = chain.module.rule(BABEL_JS_RULE);
212
+ if (include) {
213
+ castArray2(include).forEach((condition) => {
214
+ rule.include.add(condition);
215
+ });
216
+ }
217
+ if (exclude) {
218
+ castArray2(exclude).forEach((condition) => {
219
+ rule.exclude.add(condition);
220
+ });
221
+ }
222
+ const swcRule = chain.module.rules.get(CHAIN_ID.RULE.JS).use(CHAIN_ID.USE.SWC);
223
+ const swcLoader = swcRule.get("loader");
224
+ const swcOptions = swcRule.get("options");
225
+ rule.test(SCRIPT_REGEX).use(CHAIN_ID.USE.SWC).loader(swcLoader).options(swcOptions).end().use(CHAIN_ID.USE.BABEL).loader(babelLoader).options(babelOptions);
226
+ } else {
227
+ const rule = chain.module.rule(CHAIN_ID.RULE.JS);
228
+ rule.test(SCRIPT_REGEX).use(CHAIN_ID.USE.BABEL).after(CHAIN_ID.USE.SWC).loader(babelLoader).options(babelOptions);
219
229
  }
220
- const swcRule = chain.module.rules.get(CHAIN_ID.RULE.JS).use(CHAIN_ID.USE.SWC);
221
- const swcLoader = swcRule.get("loader");
222
- const swcOptions = swcRule.get("options");
223
- rule.test(SCRIPT_REGEX).use(CHAIN_ID.USE.SWC).loader(swcLoader).options(swcOptions).end().use(CHAIN_ID.USE.BABEL).loader(babelLoader).options(babelOptions);
224
- } else {
225
- const rule = chain.module.rule(CHAIN_ID.RULE.JS);
226
- rule.test(SCRIPT_REGEX).use(CHAIN_ID.USE.BABEL).after(CHAIN_ID.USE.SWC).loader(babelLoader).options(babelOptions);
227
230
  }
228
231
  });
229
232
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-babel",
3
- "version": "0.3.11",
3
+ "version": "0.4.0",
4
4
  "description": "Babel plugin for Rsbuild",
5
5
  "repository": {
6
6
  "type": "git",
@@ -28,16 +28,16 @@
28
28
  "@babel/plugin-proposal-decorators": "^7.23.2",
29
29
  "@types/babel__core": "^7.20.3",
30
30
  "upath": "2.0.1",
31
- "@rsbuild/shared": "0.3.11"
31
+ "@rsbuild/shared": "0.4.0"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@types/node": "16.x",
35
35
  "typescript": "^5.3.0",
36
- "@rsbuild/core": "0.3.11",
37
- "@scripts/test-helper": "0.3.11"
36
+ "@rsbuild/core": "0.4.0",
37
+ "@scripts/test-helper": "0.4.0"
38
38
  },
39
39
  "peerDependencies": {
40
- "@rsbuild/core": "^0.3.11"
40
+ "@rsbuild/core": "^0.4.0"
41
41
  },
42
42
  "publishConfig": {
43
43
  "access": "public",