@rsbuild/plugin-babel 1.0.3 → 1.0.4

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/README.md CHANGED
@@ -1,19 +1,19 @@
1
- <p align="center">
2
- <a href="https://rsbuild.dev" target="blank"><img src="https://github.com/web-infra-dev/rsbuild/assets/7237365/84abc13e-b620-468f-a90b-dbf28e7e9427" alt="Rsbuild Logo" /></a>
3
- </p>
1
+ # @rsbuild/plugin-babel
4
2
 
5
- # Rsbuild
3
+ An Rsbuild plugin to use Babel to transpile the code.
6
4
 
7
- The Rspack-based build tool. It's fast, out-of-the-box and extensible.
5
+ <p>
6
+ <a href="https://npmjs.com/package/@rsbuild/plugin-babel">
7
+ <img src="https://img.shields.io/npm/v/@rsbuild/plugin-babel?style=flat-square&colorA=564341&colorB=EDED91" alt="npm version" />
8
+ </a>
9
+ <img src="https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="license" />
10
+ <a href="https://npmcharts.com/compare/@rsbuild/plugin-babel?minimal=true"><img src="https://img.shields.io/npm/dm/@rsbuild/plugin-babel.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="downloads" /></a>
11
+ </p>
8
12
 
9
13
  ## Documentation
10
14
 
11
- https://rsbuild.dev/
12
-
13
- ## Contributing
14
-
15
- Please read the [Contributing Guide](https://github.com/web-infra-dev/rsbuild/blob/main/CONTRIBUTING.md).
15
+ See [Documentation](https://rsbuild.dev/plugins/list/plugin-babel).
16
16
 
17
17
  ## License
18
18
 
19
- Rsbuild is [MIT licensed](https://github.com/web-infra-dev/rsbuild/blob/main/LICENSE).
19
+ [MIT](https://github.com/web-infra-dev/rsbuild/blob/main/LICENSE).
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
- exports.id = 672;
3
- exports.ids = [672];
2
+ exports.id = 611;
3
+ exports.ids = [611];
4
4
  exports.modules = {
5
5
 
6
- /***/ 641:
6
+ /***/ 887:
7
7
  /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
8
8
 
9
9
 
10
- const { sep: DEFAULT_SEPARATOR } = __webpack_require__(17)
10
+ const { sep: DEFAULT_SEPARATOR } = __webpack_require__(928)
11
11
 
12
12
  const determineSeparator = paths => {
13
13
  for (const path of paths) {
@@ -43,7 +43,7 @@ module.exports = function commonPathPrefix (paths, sep = determineSeparator(path
43
43
 
44
44
  /***/ }),
45
45
 
46
- /***/ 672:
46
+ /***/ 611:
47
47
  /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
48
48
 
49
49
  // ESM COMPAT FLAG
@@ -55,154 +55,15 @@ __webpack_require__.d(__webpack_exports__, {
55
55
  });
56
56
 
57
57
  // EXTERNAL MODULE: external "node:process"
58
- var external_node_process_ = __webpack_require__(742);
58
+ var external_node_process_ = __webpack_require__(708);
59
59
  // EXTERNAL MODULE: external "node:path"
60
- var external_node_path_ = __webpack_require__(411);
60
+ var external_node_path_ = __webpack_require__(760);
61
61
  // EXTERNAL MODULE: external "node:fs"
62
- var external_node_fs_ = __webpack_require__(561);
62
+ var external_node_fs_ = __webpack_require__(24);
63
63
  // EXTERNAL MODULE: ../../node_modules/.pnpm/common-path-prefix@3.0.0/node_modules/common-path-prefix/index.js
64
- var common_path_prefix = __webpack_require__(641);
64
+ var common_path_prefix = __webpack_require__(887);
65
65
  // EXTERNAL MODULE: external "node:url"
66
- var external_node_url_ = __webpack_require__(41);
67
- ;// CONCATENATED MODULE: ../../node_modules/.pnpm/yocto-queue@1.0.0/node_modules/yocto-queue/index.js
68
- /*
69
- How it works:
70
- `this.#head` is an instance of `Node` which keeps track of its current value and nests another instance of `Node` that keeps the value that comes after it. When a value is provided to `.enqueue()`, the code needs to iterate through `this.#head`, going deeper and deeper to find the last value. However, iterating through every single item is slow. This problem is solved by saving a reference to the last value as `this.#tail` so that it can reference it to add a new value.
71
- */
72
-
73
- class Node {
74
- value;
75
- next;
76
-
77
- constructor(value) {
78
- this.value = value;
79
- }
80
- }
81
-
82
- class yocto_queue_Queue {
83
- #head;
84
- #tail;
85
- #size;
86
-
87
- constructor() {
88
- this.clear();
89
- }
90
-
91
- enqueue(value) {
92
- const node = new Node(value);
93
-
94
- if (this.#head) {
95
- this.#tail.next = node;
96
- this.#tail = node;
97
- } else {
98
- this.#head = node;
99
- this.#tail = node;
100
- }
101
-
102
- this.#size++;
103
- }
104
-
105
- dequeue() {
106
- const current = this.#head;
107
- if (!current) {
108
- return;
109
- }
110
-
111
- this.#head = this.#head.next;
112
- this.#size--;
113
- return current.value;
114
- }
115
-
116
- clear() {
117
- this.#head = undefined;
118
- this.#tail = undefined;
119
- this.#size = 0;
120
- }
121
-
122
- get size() {
123
- return this.#size;
124
- }
125
-
126
- * [Symbol.iterator]() {
127
- let current = this.#head;
128
-
129
- while (current) {
130
- yield current.value;
131
- current = current.next;
132
- }
133
- }
134
- }
135
-
136
- ;// CONCATENATED MODULE: ../../node_modules/.pnpm/p-limit@4.0.0/node_modules/p-limit/index.js
137
-
138
-
139
- function p_limit_pLimit(concurrency) {
140
- if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) {
141
- throw new TypeError('Expected `concurrency` to be a number from 1 and up');
142
- }
143
-
144
- const queue = new Queue();
145
- let activeCount = 0;
146
-
147
- const next = () => {
148
- activeCount--;
149
-
150
- if (queue.size > 0) {
151
- queue.dequeue()();
152
- }
153
- };
154
-
155
- const run = async (fn, resolve, args) => {
156
- activeCount++;
157
-
158
- const result = (async () => fn(...args))();
159
-
160
- resolve(result);
161
-
162
- try {
163
- await result;
164
- } catch {}
165
-
166
- next();
167
- };
168
-
169
- const enqueue = (fn, resolve, args) => {
170
- queue.enqueue(run.bind(undefined, fn, resolve, args));
171
-
172
- (async () => {
173
- // This function needs to wait until the next microtask before comparing
174
- // `activeCount` to `concurrency`, because `activeCount` is updated asynchronously
175
- // when the run function is dequeued and called. The comparison in the if-statement
176
- // needs to happen asynchronously as well to get an up-to-date value for `activeCount`.
177
- await Promise.resolve();
178
-
179
- if (activeCount < concurrency && queue.size > 0) {
180
- queue.dequeue()();
181
- }
182
- })();
183
- };
184
-
185
- const generator = (fn, ...args) => new Promise(resolve => {
186
- enqueue(fn, resolve, args);
187
- });
188
-
189
- Object.defineProperties(generator, {
190
- activeCount: {
191
- get: () => activeCount,
192
- },
193
- pendingCount: {
194
- get: () => queue.size,
195
- },
196
- clearQueue: {
197
- value: () => {
198
- queue.clear();
199
- },
200
- },
201
- });
202
-
203
- return generator;
204
- }
205
-
66
+ var external_node_url_ = __webpack_require__(136);
206
67
  ;// CONCATENATED MODULE: ../../node_modules/.pnpm/p-locate@6.0.0/node_modules/p-locate/index.js
207
68
 
208
69
 
@@ -1,6 +1,6 @@
1
1
  (() => {
2
2
  var __webpack_modules__ = {
3
- 666: (module) => {
3
+ 73: (module) => {
4
4
  const STRIP_FILENAME_RE = /^[^:]+: /;
5
5
  const format = (err) => {
6
6
  if (err instanceof SyntaxError) {
@@ -26,17 +26,17 @@
26
26
  }
27
27
  module.exports = LoaderError;
28
28
  },
29
- 598: (module, __unused_webpack_exports, __nccwpck_require__) => {
30
- const os = __nccwpck_require__(37);
31
- const path = __nccwpck_require__(17);
32
- const zlib = __nccwpck_require__(796);
33
- const crypto = __nccwpck_require__(113);
34
- const { promisify } = __nccwpck_require__(837);
35
- const { readFile, writeFile, mkdir } = __nccwpck_require__(292);
29
+ 805: (module, __unused_webpack_exports, __nccwpck_require__) => {
30
+ const os = __nccwpck_require__(857);
31
+ const path = __nccwpck_require__(928);
32
+ const zlib = __nccwpck_require__(106);
33
+ const crypto = __nccwpck_require__(982);
34
+ const { promisify } = __nccwpck_require__(23);
35
+ const { readFile, writeFile, mkdir } = __nccwpck_require__(943);
36
36
  const findCacheDirP = __nccwpck_require__
37
- .e(672)
38
- .then(__nccwpck_require__.bind(__nccwpck_require__, 672));
39
- const transform = __nccwpck_require__(470);
37
+ .e(611)
38
+ .then(__nccwpck_require__.bind(__nccwpck_require__, 611));
39
+ const transform = __nccwpck_require__(723);
40
40
  let defaultCacheDirectory = null;
41
41
  let hashType = "sha256";
42
42
  try {
@@ -122,10 +122,10 @@
122
122
  return await handleCache(directory, params);
123
123
  };
124
124
  },
125
- 769: (module, __unused_webpack_exports, __nccwpck_require__) => {
125
+ 603: (module, __unused_webpack_exports, __nccwpck_require__) => {
126
126
  let babel;
127
127
  try {
128
- babel = __nccwpck_require__(718);
128
+ babel = __nccwpck_require__(571);
129
129
  } catch (err) {
130
130
  if (err.code === "MODULE_NOT_FOUND") {
131
131
  err.message +=
@@ -140,13 +140,13 @@
140
140
  "If you want to use Babel 6.x, install 'babel-loader@7'.",
141
141
  );
142
142
  }
143
- const { version } = __nccwpck_require__(684);
144
- const cache = __nccwpck_require__(598);
145
- const transform = __nccwpck_require__(470);
146
- const injectCaller = __nccwpck_require__(172);
147
- const schema = __nccwpck_require__(383);
148
- const { isAbsolute } = __nccwpck_require__(17);
149
- const validateOptions = __nccwpck_require__(14).validate;
143
+ const { version } = __nccwpck_require__(344);
144
+ const cache = __nccwpck_require__(805);
145
+ const transform = __nccwpck_require__(723);
146
+ const injectCaller = __nccwpck_require__(273);
147
+ const schema = __nccwpck_require__(291);
148
+ const { isAbsolute } = __nccwpck_require__(928);
149
+ const validateOptions = __nccwpck_require__(979).validate;
150
150
  function subscribe(subscriber, metadata, context) {
151
151
  if (context[subscriber]) {
152
152
  context[subscriber](metadata);
@@ -327,7 +327,7 @@
327
327
  return [source, inputSourceMap];
328
328
  }
329
329
  },
330
- 172: (module) => {
330
+ 273: (module) => {
331
331
  module.exports = function injectCaller(opts, target) {
332
332
  return Object.assign({}, opts, {
333
333
  caller: Object.assign(
@@ -343,10 +343,10 @@
343
343
  });
344
344
  };
345
345
  },
346
- 470: (module, __unused_webpack_exports, __nccwpck_require__) => {
347
- const babel = __nccwpck_require__(718);
348
- const { promisify } = __nccwpck_require__(837);
349
- const LoaderError = __nccwpck_require__(666);
346
+ 723: (module, __unused_webpack_exports, __nccwpck_require__) => {
347
+ const babel = __nccwpck_require__(571);
348
+ const { promisify } = __nccwpck_require__(23);
349
+ const LoaderError = __nccwpck_require__(73);
350
350
  const transform = promisify(babel.transform);
351
351
  module.exports = async function (source, options) {
352
352
  let result;
@@ -372,59 +372,59 @@
372
372
  };
373
373
  module.exports.version = babel.version;
374
374
  },
375
- 684: (module) => {
375
+ 344: (module) => {
376
376
  "use strict";
377
377
  module.exports = require("./package.json");
378
378
  },
379
- 14: (module) => {
379
+ 979: (module) => {
380
380
  "use strict";
381
381
  module.exports = require("./schema-utils");
382
382
  },
383
- 718: (module) => {
383
+ 571: (module) => {
384
384
  "use strict";
385
385
  module.exports = require("@babel/core");
386
386
  },
387
- 113: (module) => {
387
+ 982: (module) => {
388
388
  "use strict";
389
389
  module.exports = require("crypto");
390
390
  },
391
- 292: (module) => {
391
+ 943: (module) => {
392
392
  "use strict";
393
393
  module.exports = require("fs/promises");
394
394
  },
395
- 561: (module) => {
395
+ 24: (module) => {
396
396
  "use strict";
397
397
  module.exports = require("node:fs");
398
398
  },
399
- 411: (module) => {
399
+ 760: (module) => {
400
400
  "use strict";
401
401
  module.exports = require("node:path");
402
402
  },
403
- 742: (module) => {
403
+ 708: (module) => {
404
404
  "use strict";
405
405
  module.exports = require("node:process");
406
406
  },
407
- 41: (module) => {
407
+ 136: (module) => {
408
408
  "use strict";
409
409
  module.exports = require("node:url");
410
410
  },
411
- 37: (module) => {
411
+ 857: (module) => {
412
412
  "use strict";
413
413
  module.exports = require("os");
414
414
  },
415
- 17: (module) => {
415
+ 928: (module) => {
416
416
  "use strict";
417
417
  module.exports = require("path");
418
418
  },
419
- 837: (module) => {
419
+ 23: (module) => {
420
420
  "use strict";
421
421
  module.exports = require("util");
422
422
  },
423
- 796: (module) => {
423
+ 106: (module) => {
424
424
  "use strict";
425
425
  module.exports = require("zlib");
426
426
  },
427
- 383: (module) => {
427
+ 291: (module) => {
428
428
  "use strict";
429
429
  module.exports = JSON.parse(
430
430
  '{"type":"object","properties":{"cacheDirectory":{"oneOf":[{"type":"boolean"},{"type":"string"}],"default":false},"cacheIdentifier":{"type":"string"},"cacheCompression":{"type":"boolean","default":true},"customize":{"type":"string","default":null}},"additionalProperties":true}',
@@ -495,7 +495,7 @@
495
495
  if (typeof __nccwpck_require__ !== "undefined")
496
496
  __nccwpck_require__.ab = __dirname + "/";
497
497
  (() => {
498
- var installedChunks = { 179: 1 };
498
+ var installedChunks = { 792: 1 };
499
499
  var installChunk = (chunk) => {
500
500
  var moreModules = chunk.modules,
501
501
  chunkIds = chunk.ids,
@@ -517,6 +517,6 @@
517
517
  }
518
518
  };
519
519
  })();
520
- var __webpack_exports__ = __nccwpck_require__(769);
520
+ var __webpack_exports__ = __nccwpck_require__(603);
521
521
  module.exports = __webpack_exports__;
522
522
  })();
package/dist/index.cjs CHANGED
@@ -1,334 +1,185 @@
1
1
  "use strict";
2
+ let __rslib_import_meta_url__ = 'undefined' == typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
2
3
  var __webpack_modules__ = {
3
- "@babel/core": function(module1) {
4
- module1.exports = require("@babel/core");
4
+ "@babel/core": function(module) {
5
+ module.exports = import("@babel/core");
5
6
  }
6
- };
7
- /************************************************************************/ // The module cache
8
- var __webpack_module_cache__ = {};
9
- // The require function
7
+ }, __webpack_module_cache__ = {};
10
8
  function __webpack_require__(moduleId) {
11
- // Check if module is in cache
12
9
  var cachedModule = __webpack_module_cache__[moduleId];
13
10
  if (void 0 !== cachedModule) return cachedModule.exports;
14
- // Create a new module (and put it into the cache)
15
- var module1 = __webpack_module_cache__[moduleId] = {
11
+ var module = __webpack_module_cache__[moduleId] = {
16
12
  exports: {}
17
13
  };
18
- // Execute the module function
19
- __webpack_modules__[moduleId](module1, module1.exports, __webpack_require__);
20
- // Return the exports of the module
21
- return module1.exports;
14
+ return __webpack_modules__[moduleId](module, module.exports, __webpack_require__), module.exports;
22
15
  }
23
- /************************************************************************/ // webpack/runtime/compat_get_default_export
24
- (()=>{
25
- // getDefaultExport function for compatibility with non-ESM modules
26
- __webpack_require__.n = function(module1) {
27
- var getter = module1 && module1.__esModule ? function() {
28
- return module1['default'];
29
- } : function() {
30
- return module1;
31
- };
32
- __webpack_require__.d(getter, {
33
- a: getter
34
- });
35
- return getter;
36
- };
37
- })();
38
- // webpack/runtime/create_fake_namespace_object
39
- (()=>{
40
- var getProto = Object.getPrototypeOf ? function(obj) {
41
- return Object.getPrototypeOf(obj);
42
- } : function(obj) {
43
- return obj.__proto__;
44
- };
45
- var leafPrototypes;
46
- // create a fake namespace object
47
- // mode & 1: value is a module id, require it
48
- // mode & 2: merge all properties of value into the ns
49
- // mode & 4: return value when already ns object
50
- // mode & 16: return value when it's Promise-like
51
- // mode & 8|1: behave like require
52
- __webpack_require__.t = function(value, mode) {
53
- if (1 & mode) value = this(value);
54
- if (8 & mode) return value;
55
- if ('object' == typeof value && value) {
56
- if (4 & mode && value.__esModule) return value;
57
- if (16 & mode && 'function' == typeof value.then) return value;
58
- }
59
- var ns = Object.create(null);
60
- __webpack_require__.r(ns);
61
- var def = {};
62
- leafPrototypes = leafPrototypes || [
63
- null,
64
- getProto({}),
65
- getProto([]),
66
- getProto(getProto)
67
- ];
68
- for(var current = 2 & mode && value; 'object' == typeof current && !~leafPrototypes.indexOf(current); current = getProto(current))Object.getOwnPropertyNames(current).forEach(function(key) {
69
- def[key] = function() {
70
- return value[key];
71
- };
72
- });
73
- def['default'] = function() {
74
- return value;
75
- };
76
- __webpack_require__.d(ns, def);
77
- return ns;
78
- };
79
- })();
80
- // webpack/runtime/define_property_getters
81
- (()=>{
82
- __webpack_require__.d = function(exports1, definition) {
83
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
84
- enumerable: true,
85
- get: definition[key]
86
- });
16
+ __webpack_require__.n = function(module) {
17
+ var getter = module && module.__esModule ? function() {
18
+ return module.default;
19
+ } : function() {
20
+ return module;
87
21
  };
88
- })();
89
- // webpack/runtime/has_own_property
90
- (()=>{
91
- __webpack_require__.o = function(obj, prop) {
92
- return Object.prototype.hasOwnProperty.call(obj, prop);
93
- };
94
- })();
95
- // webpack/runtime/make_namespace_object
96
- (()=>{
97
- // define __esModule on exports
98
- __webpack_require__.r = function(exports1) {
99
- if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
100
- value: 'Module'
101
- });
102
- Object.defineProperty(exports1, '__esModule', {
103
- value: true
104
- });
105
- };
106
- })();
107
- /************************************************************************/ var __webpack_exports__ = {};
108
- // ESM COMPAT FLAG
109
- __webpack_require__.r(__webpack_exports__);
110
- // EXPORTS
111
- __webpack_require__.d(__webpack_exports__, {
112
- pluginBabel: ()=>/* reexport */ pluginBabel,
113
- getBabelUtils: ()=>/* reexport */ getBabelUtils,
114
- modifyBabelLoaderOptions: ()=>/* reexport */ modifyBabelLoaderOptions,
115
- PLUGIN_BABEL_NAME: ()=>/* reexport */ PLUGIN_BABEL_NAME,
116
- getDefaultBabelOptions: ()=>/* reexport */ getDefaultBabelOptions
117
- });
118
- const external_node_fs_namespaceObject = require("node:fs");
119
- var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
120
- const external_node_module_namespaceObject = require("node:module");
121
- const external_node_path_namespaceObject = require("node:path");
122
- var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
123
- const external_node_url_namespaceObject = require("node:url");
124
- const external_deepmerge_namespaceObject = require("deepmerge");
125
- var external_deepmerge_default = /*#__PURE__*/ __webpack_require__.n(external_deepmerge_namespaceObject);
126
- const external_reduce_configs_namespaceObject = require("reduce-configs");
127
- const external_upath_namespaceObject = require("upath");
128
- var external_upath_default = /*#__PURE__*/ __webpack_require__.n(external_upath_namespaceObject);
129
- const BABEL_JS_RULE = 'babel-js';
130
- const castArray = (arr)=>{
131
- if (void 0 === arr) return [];
132
- return Array.isArray(arr) ? arr : [
133
- arr
134
- ];
135
- };
136
- const normalizeToPosixPath = (p)=>external_upath_default().normalizeSafe((0, external_node_path_namespaceObject.normalize)(p || '')).replace(/^([a-zA-Z]+):/, (_, m)=>`/${m.toLowerCase()}`);
137
- // compatible with Windows path
138
- const formatPath = (originPath)=>{
139
- if ((0, external_node_path_namespaceObject.isAbsolute)(originPath)) return originPath.split(external_node_path_namespaceObject.sep).join('/');
140
- return originPath;
141
- };
142
- const getPluginItemName = (item)=>{
143
- if ('string' == typeof item) return formatPath(item);
144
- if (Array.isArray(item) && 'string' == typeof item[0]) return formatPath(item[0]);
145
- return null;
146
- };
147
- const addPlugins = (plugins, config)=>{
148
- if (config.plugins) config.plugins.push(...plugins);
149
- else config.plugins = plugins;
150
- };
151
- const addPresets = (presets, config)=>{
152
- if (config.presets) config.presets.push(...presets);
153
- else config.presets = presets;
154
- };
155
- const removePlugins = (plugins, config)=>{
156
- if (!config.plugins) return;
157
- const removeList = castArray(plugins);
158
- config.plugins = config.plugins.filter((item)=>{
159
- const name = getPluginItemName(item);
160
- if (name) return !removeList.find((removeItem)=>name.includes(removeItem));
161
- return true;
22
+ return __webpack_require__.d(getter, {
23
+ a: getter
24
+ }), getter;
25
+ }, __webpack_require__.d = function(exports1, definition) {
26
+ for(var key in definition)__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key) && Object.defineProperty(exports1, key, {
27
+ enumerable: !0,
28
+ get: definition[key]
162
29
  });
163
- };
164
- const removePresets = (presets, config)=>{
165
- if (!config.presets) return;
166
- const removeList = castArray(presets);
167
- config.presets = config.presets.filter((item)=>{
168
- const name = getPluginItemName(item);
169
- if (name) return !removeList.find((removeItem)=>name.includes(removeItem));
170
- return true;
30
+ }, __webpack_require__.o = function(obj, prop) {
31
+ return Object.prototype.hasOwnProperty.call(obj, prop);
32
+ }, __webpack_require__.r = function(exports1) {
33
+ 'undefined' != typeof Symbol && Symbol.toStringTag && Object.defineProperty(exports1, Symbol.toStringTag, {
34
+ value: 'Module'
35
+ }), Object.defineProperty(exports1, '__esModule', {
36
+ value: !0
171
37
  });
172
38
  };
173
- const modifyPresetOptions = (presetName, options, presets = [])=>{
174
- presets.forEach((preset, index)=>{
175
- // 1. ['@babel/preset-env', ...]
176
- if (Array.isArray(preset)) {
177
- if ('string' == typeof preset[0] && normalizeToPosixPath(preset[0]).includes(presetName)) preset[1] = {
39
+ var __webpack_exports__ = {};
40
+ (()=>{
41
+ __webpack_require__.r(__webpack_exports__), __webpack_require__.d(__webpack_exports__, {
42
+ PLUGIN_BABEL_NAME: ()=>PLUGIN_BABEL_NAME,
43
+ getDefaultBabelOptions: ()=>getDefaultBabelOptions,
44
+ modifyBabelLoaderOptions: ()=>modifyBabelLoaderOptions,
45
+ getBabelUtils: ()=>getBabelUtils,
46
+ pluginBabel: ()=>pluginBabel
47
+ });
48
+ let external_node_fs_namespaceObject = require("node:fs");
49
+ var external_node_fs_default = __webpack_require__.n(external_node_fs_namespaceObject);
50
+ let external_node_module_namespaceObject = require("node:module"), external_node_path_namespaceObject = require("node:path");
51
+ var external_node_path_default = __webpack_require__.n(external_node_path_namespaceObject);
52
+ let external_node_url_namespaceObject = require("node:url"), external_deepmerge_namespaceObject = require("deepmerge");
53
+ var external_deepmerge_default = __webpack_require__.n(external_deepmerge_namespaceObject);
54
+ let external_reduce_configs_namespaceObject = require("reduce-configs"), external_upath_namespaceObject = require("upath");
55
+ var external_upath_default = __webpack_require__.n(external_upath_namespaceObject);
56
+ let BABEL_JS_RULE = 'babel-js', castArray = (arr)=>void 0 === arr ? [] : Array.isArray(arr) ? arr : [
57
+ arr
58
+ ], normalizeToPosixPath = (p)=>external_upath_default().normalizeSafe((0, external_node_path_namespaceObject.normalize)(p || '')).replace(/^([a-zA-Z]+):/, (_, m)=>`/${m.toLowerCase()}`), formatPath = (originPath)=>(0, external_node_path_namespaceObject.isAbsolute)(originPath) ? originPath.split(external_node_path_namespaceObject.sep).join('/') : originPath, getPluginItemName = (item)=>'string' == typeof item ? formatPath(item) : Array.isArray(item) && 'string' == typeof item[0] ? formatPath(item[0]) : null, addPlugins = (plugins, config)=>{
59
+ config.plugins ? config.plugins.push(...plugins) : config.plugins = plugins;
60
+ }, addPresets = (presets, config)=>{
61
+ config.presets ? config.presets.push(...presets) : config.presets = presets;
62
+ }, removePlugins = (plugins, config)=>{
63
+ if (!config.plugins) return;
64
+ let removeList = castArray(plugins);
65
+ config.plugins = config.plugins.filter((item)=>{
66
+ let name = getPluginItemName(item);
67
+ return !name || !removeList.find((removeItem)=>name.includes(removeItem));
68
+ });
69
+ }, removePresets = (presets, config)=>{
70
+ if (!config.presets) return;
71
+ let removeList = castArray(presets);
72
+ config.presets = config.presets.filter((item)=>{
73
+ let name = getPluginItemName(item);
74
+ return !name || !removeList.find((removeItem)=>name.includes(removeItem));
75
+ });
76
+ }, modifyPresetOptions = (presetName, options, presets = [])=>{
77
+ presets.forEach((preset, index)=>{
78
+ Array.isArray(preset) ? 'string' == typeof preset[0] && normalizeToPosixPath(preset[0]).includes(presetName) && (preset[1] = {
178
79
  ...preset[1] || {},
179
80
  ...options
81
+ }) : 'string' == typeof preset && normalizeToPosixPath(preset).includes(presetName) && (presets[index] = [
82
+ preset,
83
+ options
84
+ ]);
85
+ });
86
+ }, getBabelUtils = (config)=>{
87
+ let noop = ()=>{};
88
+ return {
89
+ addPlugins: (plugins)=>addPlugins(plugins, config),
90
+ addPresets: (presets)=>addPresets(presets, config),
91
+ removePlugins: (plugins)=>removePlugins(plugins, config),
92
+ removePresets: (presets)=>removePresets(presets, config),
93
+ addIncludes: noop,
94
+ addExcludes: noop,
95
+ modifyPresetEnvOptions: (options)=>modifyPresetOptions('@babel/preset-env', options, config.presets || []),
96
+ modifyPresetReactOptions: (options)=>modifyPresetOptions('@babel/preset-react', options, config.presets || [])
97
+ };
98
+ }, applyUserBabelConfig = (defaultOptions, userBabelConfig, extraBabelUtils)=>{
99
+ if (userBabelConfig) {
100
+ let babelUtils = {
101
+ ...getBabelUtils(defaultOptions),
102
+ ...extraBabelUtils
180
103
  };
181
- } else if ('string' == typeof preset && normalizeToPosixPath(preset).includes(presetName)) // 2. '@babel/preset-env'
182
- presets[index] = [
183
- preset,
184
- options
185
- ];
186
- });
187
- };
188
- const getBabelUtils = (config)=>{
189
- const noop = ()=>{};
190
- return {
191
- addPlugins: (plugins)=>addPlugins(plugins, config),
192
- addPresets: (presets)=>addPresets(presets, config),
193
- removePlugins: (plugins)=>removePlugins(plugins, config),
194
- removePresets: (presets)=>removePresets(presets, config),
195
- // `addIncludes` and `addExcludes` are noop functions by default,
196
- // It can be overridden by `extraBabelUtils`.
197
- addIncludes: noop,
198
- addExcludes: noop,
199
- // Compat `presetEnvOptions` and `presetReactOptions` in Modern.js
200
- modifyPresetEnvOptions: (options)=>modifyPresetOptions('@babel/preset-env', options, config.presets || []),
201
- modifyPresetReactOptions: (options)=>modifyPresetOptions('@babel/preset-react', options, config.presets || [])
104
+ return (0, external_reduce_configs_namespaceObject.reduceConfigsWithContext)({
105
+ initial: defaultOptions,
106
+ config: userBabelConfig,
107
+ ctx: babelUtils
108
+ });
109
+ }
110
+ return defaultOptions;
111
+ }, modifyBabelLoaderOptions = ({ chain, CHAIN_ID, modifier })=>{
112
+ for (let ruleId of [
113
+ CHAIN_ID.RULE.JS,
114
+ CHAIN_ID.RULE.JS_DATA_URI,
115
+ BABEL_JS_RULE
116
+ ])if (chain.module.rules.has(ruleId)) {
117
+ let rule = chain.module.rule(ruleId);
118
+ rule.uses.has(CHAIN_ID.USE.BABEL) && rule.use(CHAIN_ID.USE.BABEL).tap(modifier);
119
+ }
120
+ }, plugin_dirname = external_node_path_default().dirname((0, external_node_url_namespaceObject.fileURLToPath)(__rslib_import_meta_url__)), plugin_require = (0, external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__), PLUGIN_BABEL_NAME = 'rsbuild:babel', SCRIPT_REGEX = /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/, DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS = {
121
+ allowNamespaces: !0,
122
+ allExtensions: !0,
123
+ allowDeclareFields: !0,
124
+ optimizeConstEnums: !0,
125
+ isTSX: !0
202
126
  };
203
- };
204
- const applyUserBabelConfig = (defaultOptions, userBabelConfig, extraBabelUtils)=>{
205
- if (userBabelConfig) {
206
- const babelUtils = {
207
- ...getBabelUtils(defaultOptions),
208
- ...extraBabelUtils
209
- };
210
- return (0, external_reduce_configs_namespaceObject.reduceConfigsWithContext)({
211
- initial: defaultOptions,
212
- config: userBabelConfig,
213
- ctx: babelUtils
214
- });
127
+ async function getCacheIdentifier(options) {
128
+ let identifier = `${process.env.NODE_ENV}${JSON.stringify(options)}`, { version: coreVersion } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "@babel/core")), loaderVersion = JSON.parse(await external_node_fs_default().promises.readFile((0, external_node_path_namespaceObject.join)(plugin_dirname, '../compiled/babel-loader/package.json'), 'utf-8')).version ?? '';
129
+ return identifier + `@babel/core@${coreVersion}babel-loader@${loaderVersion}`;
215
130
  }
216
- return defaultOptions;
217
- };
218
- const modifyBabelLoaderOptions = ({ chain, CHAIN_ID, modifier })=>{
219
- const ruleIds = [
220
- CHAIN_ID.RULE.JS,
221
- CHAIN_ID.RULE.JS_DATA_URI,
222
- BABEL_JS_RULE
223
- ];
224
- for (const ruleId of ruleIds)if (chain.module.rules.has(ruleId)) {
225
- const rule = chain.module.rule(ruleId);
226
- if (rule.uses.has(CHAIN_ID.USE.BABEL)) rule.use(CHAIN_ID.USE.BABEL).tap(modifier);
227
- }
228
- };
229
- const plugin_dirname = external_node_path_default().dirname((0, external_node_url_namespaceObject.fileURLToPath)(/*#__PURE__*/ function() {
230
- 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;
231
- }()));
232
- const plugin_require = (0, external_node_module_namespaceObject.createRequire)(/*#__PURE__*/ function() {
233
- 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;
234
- }());
235
- const PLUGIN_BABEL_NAME = 'rsbuild:babel';
236
- const SCRIPT_REGEX = /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/;
237
- /**
238
- * The `@babel/preset-typescript` default options.
239
- */ const DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS = {
240
- allowNamespaces: true,
241
- allExtensions: true,
242
- allowDeclareFields: true,
243
- // aligns Babel's behavior with TypeScript's default behavior.
244
- // https://babeljs.io/docs/en/babel-preset-typescript#optimizeconstenums
245
- optimizeConstEnums: true,
246
- isTSX: true
247
- };
248
- function getCacheDirectory(context, cacheDirectory) {
249
- if (cacheDirectory) return (0, external_node_path_namespaceObject.isAbsolute)(cacheDirectory) ? cacheDirectory : (0, external_node_path_namespaceObject.join)(context.rootPath, cacheDirectory);
250
- return (0, external_node_path_namespaceObject.join)(context.cachePath);
251
- }
252
- async function getCacheIdentifier(options) {
253
- let identifier = `${process.env.NODE_ENV}${JSON.stringify(options)}`;
254
- const { version: coreVersion } = await Promise.resolve().then(__webpack_require__.t.bind(__webpack_require__, "@babel/core", 23));
255
- const rawPkgJson = await external_node_fs_default().promises.readFile((0, external_node_path_namespaceObject.join)(plugin_dirname, '../compiled/babel-loader/package.json'), 'utf-8');
256
- const loaderVersion = JSON.parse(rawPkgJson).version ?? '';
257
- identifier += `@babel/core@${coreVersion}`;
258
- identifier += `babel-loader@${loaderVersion}`;
259
- return identifier;
260
- }
261
- const getDefaultBabelOptions = (config, context)=>{
262
- const isLegacyDecorators = 'legacy' === config.source.decorators.version;
263
- const options = {
264
- babelrc: false,
265
- configFile: false,
266
- compact: 'production' === config.mode,
267
- plugins: [
268
- [
269
- plugin_require.resolve('@babel/plugin-proposal-decorators'),
270
- config.source.decorators
131
+ let getDefaultBabelOptions = (config, context)=>{
132
+ let isLegacyDecorators = 'legacy' === config.source.decorators.version, options = {
133
+ babelrc: !1,
134
+ configFile: !1,
135
+ compact: 'production' === config.mode,
136
+ plugins: [
137
+ [
138
+ plugin_require.resolve('@babel/plugin-proposal-decorators'),
139
+ config.source.decorators
140
+ ],
141
+ ...isLegacyDecorators ? [
142
+ plugin_require.resolve('@babel/plugin-transform-class-properties')
143
+ ] : []
271
144
  ],
272
- // If you are using @babel/preset-env and legacy decorators, you must ensure the class elements transform is enabled regardless of your targets, because Babel only supports compiling legacy decorators when also compiling class properties:
273
- // see https://babeljs.io/docs/babel-plugin-proposal-decorators#legacy
274
- ...isLegacyDecorators ? [
275
- plugin_require.resolve('@babel/plugin-transform-class-properties')
276
- ] : []
277
- ],
278
- presets: [
279
- // TODO: only apply preset-typescript for ts file (isTSX & allExtensions false)
280
- [
281
- plugin_require.resolve('@babel/preset-typescript'),
282
- DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS
145
+ presets: [
146
+ [
147
+ plugin_require.resolve("@babel/preset-typescript"),
148
+ DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS
149
+ ]
283
150
  ]
284
- ]
285
- };
286
- const { buildCache } = config.performance;
287
- // Rspack does not yet support persistent cache
288
- // so we use babel-loader's cache to improve rebuild performance
289
- if (buildCache && 'rspack' === context.bundlerType) {
290
- const cacheDirectory = getCacheDirectory(context, 'boolean' == typeof buildCache ? void 0 : buildCache.cacheDirectory);
291
- // turn off compression to reduce overhead
292
- options.cacheCompression = false;
293
- options.cacheDirectory = (0, external_node_path_namespaceObject.join)(cacheDirectory, 'babel-loader');
294
- }
295
- return options;
296
- };
297
- const pluginBabel = (options = {})=>({
298
- name: PLUGIN_BABEL_NAME,
299
- setup (api) {
300
- const getBabelOptions = async (environment)=>{
301
- const { config } = environment;
302
- const baseOptions = getDefaultBabelOptions(config, api.context);
303
- const mergedOptions = applyUserBabelConfig(external_deepmerge_default()({}, baseOptions), options.babelLoaderOptions);
304
- // calculate cacheIdentifier with the merged options
305
- if (mergedOptions.cacheDirectory && !mergedOptions.cacheIdentifier) mergedOptions.cacheIdentifier = await getCacheIdentifier(mergedOptions);
306
- return mergedOptions;
307
- };
308
- api.modifyBundlerChain({
309
- order: 'pre',
310
- handler: async (chain, { CHAIN_ID, environment })=>{
311
- const babelOptions = await getBabelOptions(environment);
312
- const babelLoader = external_node_path_default().resolve(plugin_dirname, '../compiled/babel-loader/index.js');
313
- const { include, exclude } = options;
314
- if (include || exclude) {
315
- const rule = chain.module.rule(BABEL_JS_RULE) // run babel loader before the builtin SWC loader
316
- // https://stackoverflow.com/questions/32234329/what-is-the-loader-order-for-webpack
317
- .after(CHAIN_ID.RULE.JS);
318
- if (include) for (const condition of castArray(include))rule.include.add(condition);
319
- if (exclude) for (const condition of castArray(exclude))rule.exclude.add(condition);
320
- rule.test(SCRIPT_REGEX).use(CHAIN_ID.USE.BABEL).loader(babelLoader).options(babelOptions);
321
- } else {
322
- // already set source.include / exclude in plugin-swc
323
- const rule = chain.module.rule(CHAIN_ID.RULE.JS);
324
- rule.test(SCRIPT_REGEX).use(CHAIN_ID.USE.BABEL).after(CHAIN_ID.USE.SWC).loader(babelLoader).options(babelOptions);
325
- }
326
- }
327
- });
151
+ }, { buildCache = !0 } = config.performance;
152
+ if (buildCache && 'rspack' === context.bundlerType) {
153
+ let cacheDirectory = function(context, cacheDirectory) {
154
+ return cacheDirectory ? (0, external_node_path_namespaceObject.isAbsolute)(cacheDirectory) ? cacheDirectory : (0, external_node_path_namespaceObject.join)(context.rootPath, cacheDirectory) : (0, external_node_path_namespaceObject.join)(context.cachePath);
155
+ }(context, 'boolean' == typeof buildCache ? void 0 : buildCache.cacheDirectory);
156
+ options.cacheCompression = !1, options.cacheDirectory = (0, external_node_path_namespaceObject.join)(cacheDirectory, 'babel-loader');
328
157
  }
329
- });
158
+ return options;
159
+ }, pluginBabel = (options = {})=>({
160
+ name: PLUGIN_BABEL_NAME,
161
+ setup (api) {
162
+ let getBabelOptions = async (environment)=>{
163
+ let { config } = environment, baseOptions = getDefaultBabelOptions(config, api.context), mergedOptions = applyUserBabelConfig(external_deepmerge_default()({}, baseOptions), options.babelLoaderOptions);
164
+ return mergedOptions.cacheDirectory && !mergedOptions.cacheIdentifier && (mergedOptions.cacheIdentifier = await getCacheIdentifier(mergedOptions)), mergedOptions;
165
+ };
166
+ api.modifyBundlerChain({
167
+ order: 'pre',
168
+ handler: async (chain, { CHAIN_ID, environment })=>{
169
+ let babelOptions = await getBabelOptions(environment), babelLoader = external_node_path_default().resolve(plugin_dirname, '../compiled/babel-loader/index.js'), { include, exclude } = options;
170
+ if (include || exclude) {
171
+ let rule = chain.module.rule(BABEL_JS_RULE).after(CHAIN_ID.RULE.JS);
172
+ if (include) for (let condition of castArray(include))rule.include.add(condition);
173
+ if (exclude) for (let condition of castArray(exclude))rule.exclude.add(condition);
174
+ rule.test(SCRIPT_REGEX).use(CHAIN_ID.USE.BABEL).loader(babelLoader).options(babelOptions);
175
+ } else chain.module.rule(CHAIN_ID.RULE.JS).test(SCRIPT_REGEX).use(CHAIN_ID.USE.BABEL).after(CHAIN_ID.USE.SWC).loader(babelLoader).options(babelOptions);
176
+ }
177
+ });
178
+ }
179
+ });
180
+ })();
330
181
  var __webpack_export_target__ = exports;
331
- for(var i in __webpack_exports__)__webpack_export_target__[i] = __webpack_exports__[i];
332
- if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
333
- value: true
182
+ for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
183
+ __webpack_exports__.__esModule && Object.defineProperty(__webpack_export_target__, '__esModule', {
184
+ value: !0
334
185
  });
package/dist/index.js CHANGED
@@ -1,203 +1,129 @@
1
- import * as __WEBPACK_EXTERNAL_MODULE_node_fs__ from "node:fs";
2
- import * as __WEBPACK_EXTERNAL_MODULE_node_module__ from "node:module";
3
- import * as __WEBPACK_EXTERNAL_MODULE_node_path__ from "node:path";
4
- import * as __WEBPACK_EXTERNAL_MODULE_node_url__ from "node:url";
1
+ import * as __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__ from "node:fs";
2
+ import * as __WEBPACK_EXTERNAL_MODULE_node_module_ab9f2194__ from "node:module";
3
+ import * as __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__ from "node:path";
4
+ import * as __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__ from "node:url";
5
5
  import * as __WEBPACK_EXTERNAL_MODULE_deepmerge__ from "deepmerge";
6
- import * as __WEBPACK_EXTERNAL_MODULE_reduce_configs__ from "reduce-configs";
6
+ import * as __WEBPACK_EXTERNAL_MODULE_reduce_configs_02786df6__ from "reduce-configs";
7
7
  import * as __WEBPACK_EXTERNAL_MODULE_upath__ from "upath";
8
- const BABEL_JS_RULE = 'babel-js';
9
- const castArray = (arr)=>{
10
- if (void 0 === arr) return [];
11
- return Array.isArray(arr) ? arr : [
8
+ let BABEL_JS_RULE = 'babel-js', castArray = (arr)=>void 0 === arr ? [] : Array.isArray(arr) ? arr : [
12
9
  arr
13
- ];
14
- };
15
- const normalizeToPosixPath = (p)=>__WEBPACK_EXTERNAL_MODULE_upath__["default"].normalizeSafe((0, __WEBPACK_EXTERNAL_MODULE_node_path__.normalize)(p || '')).replace(/^([a-zA-Z]+):/, (_, m)=>`/${m.toLowerCase()}`);
16
- // compatible with Windows path
17
- const formatPath = (originPath)=>{
18
- if ((0, __WEBPACK_EXTERNAL_MODULE_node_path__.isAbsolute)(originPath)) return originPath.split(__WEBPACK_EXTERNAL_MODULE_node_path__.sep).join('/');
19
- return originPath;
20
- };
21
- const getPluginItemName = (item)=>{
22
- if ('string' == typeof item) return formatPath(item);
23
- if (Array.isArray(item) && 'string' == typeof item[0]) return formatPath(item[0]);
24
- return null;
25
- };
26
- const addPlugins = (plugins, config)=>{
27
- if (config.plugins) config.plugins.push(...plugins);
28
- else config.plugins = plugins;
29
- };
30
- const addPresets = (presets, config)=>{
31
- if (config.presets) config.presets.push(...presets);
32
- else config.presets = presets;
33
- };
34
- const removePlugins = (plugins, config)=>{
10
+ ], normalizeToPosixPath = (p)=>__WEBPACK_EXTERNAL_MODULE_upath__.default.normalizeSafe((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.normalize)(p || '')).replace(/^([a-zA-Z]+):/, (_, m)=>`/${m.toLowerCase()}`), formatPath = (originPath)=>(0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.isAbsolute)(originPath) ? originPath.split(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.sep).join('/') : originPath, getPluginItemName = (item)=>'string' == typeof item ? formatPath(item) : Array.isArray(item) && 'string' == typeof item[0] ? formatPath(item[0]) : null, addPlugins = (plugins, config)=>{
11
+ config.plugins ? config.plugins.push(...plugins) : config.plugins = plugins;
12
+ }, addPresets = (presets, config)=>{
13
+ config.presets ? config.presets.push(...presets) : config.presets = presets;
14
+ }, removePlugins = (plugins, config)=>{
35
15
  if (!config.plugins) return;
36
- const removeList = castArray(plugins);
16
+ let removeList = castArray(plugins);
37
17
  config.plugins = config.plugins.filter((item)=>{
38
- const name = getPluginItemName(item);
39
- if (name) return !removeList.find((removeItem)=>name.includes(removeItem));
40
- return true;
18
+ let name = getPluginItemName(item);
19
+ return !name || !removeList.find((removeItem)=>name.includes(removeItem));
41
20
  });
42
- };
43
- const removePresets = (presets, config)=>{
21
+ }, removePresets = (presets, config)=>{
44
22
  if (!config.presets) return;
45
- const removeList = castArray(presets);
23
+ let removeList = castArray(presets);
46
24
  config.presets = config.presets.filter((item)=>{
47
- const name = getPluginItemName(item);
48
- if (name) return !removeList.find((removeItem)=>name.includes(removeItem));
49
- return true;
25
+ let name = getPluginItemName(item);
26
+ return !name || !removeList.find((removeItem)=>name.includes(removeItem));
50
27
  });
51
- };
52
- const modifyPresetOptions = (presetName, options, presets = [])=>{
28
+ }, modifyPresetOptions = (presetName, options, presets = [])=>{
53
29
  presets.forEach((preset, index)=>{
54
- // 1. ['@babel/preset-env', ...]
55
- if (Array.isArray(preset)) {
56
- if ('string' == typeof preset[0] && normalizeToPosixPath(preset[0]).includes(presetName)) preset[1] = {
57
- ...preset[1] || {},
58
- ...options
59
- };
60
- } else if ('string' == typeof preset && normalizeToPosixPath(preset).includes(presetName)) // 2. '@babel/preset-env'
61
- presets[index] = [
30
+ Array.isArray(preset) ? 'string' == typeof preset[0] && normalizeToPosixPath(preset[0]).includes(presetName) && (preset[1] = {
31
+ ...preset[1] || {},
32
+ ...options
33
+ }) : 'string' == typeof preset && normalizeToPosixPath(preset).includes(presetName) && (presets[index] = [
62
34
  preset,
63
35
  options
64
- ];
36
+ ]);
65
37
  });
66
- };
67
- const getBabelUtils = (config)=>{
68
- const noop = ()=>{};
38
+ }, getBabelUtils = (config)=>{
39
+ let noop = ()=>{};
69
40
  return {
70
41
  addPlugins: (plugins)=>addPlugins(plugins, config),
71
42
  addPresets: (presets)=>addPresets(presets, config),
72
43
  removePlugins: (plugins)=>removePlugins(plugins, config),
73
44
  removePresets: (presets)=>removePresets(presets, config),
74
- // `addIncludes` and `addExcludes` are noop functions by default,
75
- // It can be overridden by `extraBabelUtils`.
76
45
  addIncludes: noop,
77
46
  addExcludes: noop,
78
- // Compat `presetEnvOptions` and `presetReactOptions` in Modern.js
79
47
  modifyPresetEnvOptions: (options)=>modifyPresetOptions('@babel/preset-env', options, config.presets || []),
80
48
  modifyPresetReactOptions: (options)=>modifyPresetOptions('@babel/preset-react', options, config.presets || [])
81
49
  };
82
- };
83
- const applyUserBabelConfig = (defaultOptions, userBabelConfig, extraBabelUtils)=>{
50
+ }, applyUserBabelConfig = (defaultOptions, userBabelConfig, extraBabelUtils)=>{
84
51
  if (userBabelConfig) {
85
- const babelUtils = {
52
+ let babelUtils = {
86
53
  ...getBabelUtils(defaultOptions),
87
54
  ...extraBabelUtils
88
55
  };
89
- return (0, __WEBPACK_EXTERNAL_MODULE_reduce_configs__.reduceConfigsWithContext)({
56
+ return (0, __WEBPACK_EXTERNAL_MODULE_reduce_configs_02786df6__.reduceConfigsWithContext)({
90
57
  initial: defaultOptions,
91
58
  config: userBabelConfig,
92
59
  ctx: babelUtils
93
60
  });
94
61
  }
95
62
  return defaultOptions;
96
- };
97
- const modifyBabelLoaderOptions = ({ chain, CHAIN_ID, modifier })=>{
98
- const ruleIds = [
63
+ }, modifyBabelLoaderOptions = ({ chain, CHAIN_ID, modifier })=>{
64
+ for (let ruleId of [
99
65
  CHAIN_ID.RULE.JS,
100
66
  CHAIN_ID.RULE.JS_DATA_URI,
101
67
  BABEL_JS_RULE
102
- ];
103
- for (const ruleId of ruleIds)if (chain.module.rules.has(ruleId)) {
104
- const rule = chain.module.rule(ruleId);
105
- if (rule.uses.has(CHAIN_ID.USE.BABEL)) rule.use(CHAIN_ID.USE.BABEL).tap(modifier);
68
+ ])if (chain.module.rules.has(ruleId)) {
69
+ let rule = chain.module.rule(ruleId);
70
+ rule.uses.has(CHAIN_ID.USE.BABEL) && rule.use(CHAIN_ID.USE.BABEL).tap(modifier);
106
71
  }
72
+ }, plugin_dirname = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.dirname((0, __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__.fileURLToPath)(import.meta.url)), plugin_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module_ab9f2194__.createRequire)(import.meta.url), PLUGIN_BABEL_NAME = 'rsbuild:babel', SCRIPT_REGEX = /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/, DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS = {
73
+ allowNamespaces: !0,
74
+ allExtensions: !0,
75
+ allowDeclareFields: !0,
76
+ optimizeConstEnums: !0,
77
+ isTSX: !0
107
78
  };
108
- const plugin_dirname = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].dirname((0, __WEBPACK_EXTERNAL_MODULE_node_url__.fileURLToPath)(import.meta.url));
109
- const plugin_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module__.createRequire)(import.meta.url);
110
- const PLUGIN_BABEL_NAME = 'rsbuild:babel';
111
- const SCRIPT_REGEX = /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/;
112
- /**
113
- * The `@babel/preset-typescript` default options.
114
- */ const DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS = {
115
- allowNamespaces: true,
116
- allExtensions: true,
117
- allowDeclareFields: true,
118
- // aligns Babel's behavior with TypeScript's default behavior.
119
- // https://babeljs.io/docs/en/babel-preset-typescript#optimizeconstenums
120
- optimizeConstEnums: true,
121
- isTSX: true
122
- };
123
- function getCacheDirectory(context, cacheDirectory) {
124
- if (cacheDirectory) return (0, __WEBPACK_EXTERNAL_MODULE_node_path__.isAbsolute)(cacheDirectory) ? cacheDirectory : (0, __WEBPACK_EXTERNAL_MODULE_node_path__.join)(context.rootPath, cacheDirectory);
125
- return (0, __WEBPACK_EXTERNAL_MODULE_node_path__.join)(context.cachePath);
126
- }
127
79
  async function getCacheIdentifier(options) {
128
- let identifier = `${process.env.NODE_ENV}${JSON.stringify(options)}`;
129
- const { version: coreVersion } = await import("@babel/core");
130
- const rawPkgJson = await __WEBPACK_EXTERNAL_MODULE_node_fs__["default"].promises.readFile((0, __WEBPACK_EXTERNAL_MODULE_node_path__.join)(plugin_dirname, '../compiled/babel-loader/package.json'), 'utf-8');
131
- const loaderVersion = JSON.parse(rawPkgJson).version ?? '';
132
- identifier += `@babel/core@${coreVersion}`;
133
- identifier += `babel-loader@${loaderVersion}`;
134
- return identifier;
80
+ let identifier = `${process.env.NODE_ENV}${JSON.stringify(options)}`, { version: coreVersion } = await import("@babel/core"), loaderVersion = JSON.parse(await __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.default.promises.readFile((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(plugin_dirname, '../compiled/babel-loader/package.json'), 'utf-8')).version ?? '';
81
+ return identifier + `@babel/core@${coreVersion}babel-loader@${loaderVersion}`;
135
82
  }
136
- const getDefaultBabelOptions = (config, context)=>{
137
- const isLegacyDecorators = 'legacy' === config.source.decorators.version;
138
- const options = {
139
- babelrc: false,
140
- configFile: false,
83
+ let getDefaultBabelOptions = (config, context)=>{
84
+ let isLegacyDecorators = 'legacy' === config.source.decorators.version, options = {
85
+ babelrc: !1,
86
+ configFile: !1,
141
87
  compact: 'production' === config.mode,
142
88
  plugins: [
143
89
  [
144
90
  plugin_require.resolve('@babel/plugin-proposal-decorators'),
145
91
  config.source.decorators
146
92
  ],
147
- // If you are using @babel/preset-env and legacy decorators, you must ensure the class elements transform is enabled regardless of your targets, because Babel only supports compiling legacy decorators when also compiling class properties:
148
- // see https://babeljs.io/docs/babel-plugin-proposal-decorators#legacy
149
93
  ...isLegacyDecorators ? [
150
94
  plugin_require.resolve('@babel/plugin-transform-class-properties')
151
95
  ] : []
152
96
  ],
153
97
  presets: [
154
- // TODO: only apply preset-typescript for ts file (isTSX & allExtensions false)
155
98
  [
156
- plugin_require.resolve('@babel/preset-typescript'),
99
+ plugin_require.resolve("@babel/preset-typescript"),
157
100
  DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS
158
101
  ]
159
102
  ]
160
- };
161
- const { buildCache } = config.performance;
162
- // Rspack does not yet support persistent cache
163
- // so we use babel-loader's cache to improve rebuild performance
103
+ }, { buildCache = !0 } = config.performance;
164
104
  if (buildCache && 'rspack' === context.bundlerType) {
165
- const cacheDirectory = getCacheDirectory(context, 'boolean' == typeof buildCache ? void 0 : buildCache.cacheDirectory);
166
- // turn off compression to reduce overhead
167
- options.cacheCompression = false;
168
- options.cacheDirectory = (0, __WEBPACK_EXTERNAL_MODULE_node_path__.join)(cacheDirectory, 'babel-loader');
105
+ var cacheDirectory;
106
+ let cacheDirectory1 = (cacheDirectory = 'boolean' == typeof buildCache ? void 0 : buildCache.cacheDirectory) ? (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.isAbsolute)(cacheDirectory) ? cacheDirectory : (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(context.rootPath, cacheDirectory) : (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(context.cachePath);
107
+ options.cacheCompression = !1, options.cacheDirectory = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(cacheDirectory1, 'babel-loader');
169
108
  }
170
109
  return options;
171
- };
172
- const pluginBabel = (options = {})=>({
110
+ }, pluginBabel = (options = {})=>({
173
111
  name: PLUGIN_BABEL_NAME,
174
112
  setup (api) {
175
- const getBabelOptions = async (environment)=>{
176
- const { config } = environment;
177
- const baseOptions = getDefaultBabelOptions(config, api.context);
178
- const mergedOptions = applyUserBabelConfig((0, __WEBPACK_EXTERNAL_MODULE_deepmerge__["default"])({}, baseOptions), options.babelLoaderOptions);
179
- // calculate cacheIdentifier with the merged options
180
- if (mergedOptions.cacheDirectory && !mergedOptions.cacheIdentifier) mergedOptions.cacheIdentifier = await getCacheIdentifier(mergedOptions);
181
- return mergedOptions;
113
+ let getBabelOptions = async (environment)=>{
114
+ let { config } = environment, baseOptions = getDefaultBabelOptions(config, api.context), mergedOptions = applyUserBabelConfig((0, __WEBPACK_EXTERNAL_MODULE_deepmerge__.default)({}, baseOptions), options.babelLoaderOptions);
115
+ return mergedOptions.cacheDirectory && !mergedOptions.cacheIdentifier && (mergedOptions.cacheIdentifier = await getCacheIdentifier(mergedOptions)), mergedOptions;
182
116
  };
183
117
  api.modifyBundlerChain({
184
118
  order: 'pre',
185
119
  handler: async (chain, { CHAIN_ID, environment })=>{
186
- const babelOptions = await getBabelOptions(environment);
187
- const babelLoader = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].resolve(plugin_dirname, '../compiled/babel-loader/index.js');
188
- const { include, exclude } = options;
120
+ let babelOptions = await getBabelOptions(environment), babelLoader = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.resolve(plugin_dirname, '../compiled/babel-loader/index.js'), { include, exclude } = options;
189
121
  if (include || exclude) {
190
- const rule = chain.module.rule(BABEL_JS_RULE) // run babel loader before the builtin SWC loader
191
- // https://stackoverflow.com/questions/32234329/what-is-the-loader-order-for-webpack
192
- .after(CHAIN_ID.RULE.JS);
193
- if (include) for (const condition of castArray(include))rule.include.add(condition);
194
- if (exclude) for (const condition of castArray(exclude))rule.exclude.add(condition);
122
+ let rule = chain.module.rule(BABEL_JS_RULE).after(CHAIN_ID.RULE.JS);
123
+ if (include) for (let condition of castArray(include))rule.include.add(condition);
124
+ if (exclude) for (let condition of castArray(exclude))rule.exclude.add(condition);
195
125
  rule.test(SCRIPT_REGEX).use(CHAIN_ID.USE.BABEL).loader(babelLoader).options(babelOptions);
196
- } else {
197
- // already set source.include / exclude in plugin-swc
198
- const rule = chain.module.rule(CHAIN_ID.RULE.JS);
199
- rule.test(SCRIPT_REGEX).use(CHAIN_ID.USE.BABEL).after(CHAIN_ID.USE.SWC).loader(babelLoader).options(babelOptions);
200
- }
126
+ } else chain.module.rule(CHAIN_ID.RULE.JS).test(SCRIPT_REGEX).use(CHAIN_ID.USE.BABEL).after(CHAIN_ID.USE.SWC).loader(babelLoader).options(babelOptions);
201
127
  }
202
128
  });
203
129
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-babel",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Babel plugin for Rsbuild",
5
5
  "repository": {
6
6
  "type": "git",
@@ -23,21 +23,22 @@
23
23
  "compiled"
24
24
  ],
25
25
  "dependencies": {
26
- "@babel/core": "^7.26.0",
26
+ "@babel/core": "^7.26.9",
27
27
  "@babel/plugin-proposal-decorators": "^7.25.9",
28
28
  "@babel/plugin-transform-class-properties": "^7.25.9",
29
29
  "@babel/preset-typescript": "^7.26.0",
30
30
  "@types/babel__core": "^7.20.5",
31
31
  "deepmerge": "^4.3.1",
32
- "reduce-configs": "^1.0.0",
32
+ "reduce-configs": "^1.1.0",
33
33
  "upath": "2.0.1"
34
34
  },
35
35
  "devDependencies": {
36
- "@types/node": "18.x",
36
+ "@rslib/core": "0.4.1",
37
+ "@types/node": "^22.13.4",
37
38
  "babel-loader": "9.2.1",
38
- "prebundle": "1.2.2",
39
- "typescript": "^5.6.3",
40
- "@rsbuild/core": "1.0.19",
39
+ "prebundle": "1.2.7",
40
+ "typescript": "^5.7.3",
41
+ "@rsbuild/core": "1.2.9",
41
42
  "@scripts/test-helper": "1.0.1"
42
43
  },
43
44
  "peerDependencies": {