@rsbuild/plugin-babel 1.0.2 → 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
- 69: (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
- 856: (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__(694);
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
- 98: (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__(856);
145
- const transform = __nccwpck_require__(694);
146
- const injectCaller = __nccwpck_require__(635);
147
- const schema = __nccwpck_require__(441);
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
- 635: (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
- 694: (module, __unused_webpack_exports, __nccwpck_require__) => {
347
- const babel = __nccwpck_require__(718);
348
- const { promisify } = __nccwpck_require__(837);
349
- const LoaderError = __nccwpck_require__(69);
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
- 441: (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__(98);
520
+ var __webpack_exports__ = __nccwpck_require__(603);
521
521
  module.exports = __webpack_exports__;
522
522
  })();
package/dist/index.cjs CHANGED
@@ -1,336 +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-harmony 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_deepmerge_namespaceObject = require("deepmerge");
124
- var external_deepmerge_default = /*#__PURE__*/ __webpack_require__.n(external_deepmerge_namespaceObject);
125
- const external_reduce_configs_namespaceObject = require("reduce-configs");
126
- const external_upath_namespaceObject = require("upath");
127
- var external_upath_default = /*#__PURE__*/ __webpack_require__.n(external_upath_namespaceObject);
128
- const BABEL_JS_RULE = 'babel-js';
129
- const castArray = (arr)=>{
130
- if (void 0 === arr) return [];
131
- return Array.isArray(arr) ? arr : [
132
- arr
133
- ];
134
- };
135
- const normalizeToPosixPath = (p)=>external_upath_default().normalizeSafe((0, external_node_path_namespaceObject.normalize)(p || '')).replace(/^([a-zA-Z]+):/, (_, m)=>`/${m.toLowerCase()}`);
136
- // compatible with windows path
137
- const formatPath = (originPath)=>{
138
- if ((0, external_node_path_namespaceObject.isAbsolute)(originPath)) return originPath.split(external_node_path_namespaceObject.sep).join('/');
139
- return originPath;
140
- };
141
- const getPluginItemName = (item)=>{
142
- if ('string' == typeof item) return formatPath(item);
143
- if (Array.isArray(item) && 'string' == typeof item[0]) return formatPath(item[0]);
144
- return null;
145
- };
146
- const addPlugins = (plugins, config)=>{
147
- if (config.plugins) config.plugins.push(...plugins);
148
- else config.plugins = plugins;
149
- };
150
- const addPresets = (presets, config)=>{
151
- if (config.presets) config.presets.push(...presets);
152
- else config.presets = presets;
153
- };
154
- const removePlugins = (plugins, config)=>{
155
- if (!config.plugins) return;
156
- const removeList = castArray(plugins);
157
- config.plugins = config.plugins.filter((item)=>{
158
- const name = getPluginItemName(item);
159
- if (name) return !removeList.find((removeItem)=>name.includes(removeItem));
160
- 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]
161
29
  });
162
- };
163
- const removePresets = (presets, config)=>{
164
- if (!config.presets) return;
165
- const removeList = castArray(presets);
166
- config.presets = config.presets.filter((item)=>{
167
- const name = getPluginItemName(item);
168
- if (name) return !removeList.find((removeItem)=>name.includes(removeItem));
169
- 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
170
37
  });
171
38
  };
172
- const modifyPresetOptions = function(presetName, options) {
173
- let presets = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : [];
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
- });
215
- }
216
- return defaultOptions;
217
- };
218
- const modifyBabelLoaderOptions = (param)=>{
219
- let { chain, CHAIN_ID, modifier } = param;
220
- const ruleIds = [
221
- CHAIN_ID.RULE.JS,
222
- CHAIN_ID.RULE.JS_DATA_URI,
223
- BABEL_JS_RULE
224
- ];
225
- for (const ruleId of ruleIds)if (chain.module.rules.has(ruleId)) {
226
- const rule = chain.module.rule(ruleId);
227
- if (rule.uses.has(CHAIN_ID.USE.BABEL)) rule.use(CHAIN_ID.USE.BABEL).tap(modifier);
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}`;
228
130
  }
229
- };
230
- const plugin_require = (0, external_node_module_namespaceObject.createRequire)(/*#__PURE__*/ function() {
231
- 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;
232
- }());
233
- const PLUGIN_BABEL_NAME = 'rsbuild:babel';
234
- const SCRIPT_REGEX = /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/;
235
- /**
236
- * The `@babel/preset-typescript` default options.
237
- */ const DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS = {
238
- allowNamespaces: true,
239
- allExtensions: true,
240
- allowDeclareFields: true,
241
- // aligns Babel's behavior with TypeScript's default behavior.
242
- // https://babeljs.io/docs/en/babel-preset-typescript#optimizeconstenums
243
- optimizeConstEnums: true,
244
- isTSX: true
245
- };
246
- function getCacheDirectory(context, cacheDirectory) {
247
- if (cacheDirectory) return (0, external_node_path_namespaceObject.isAbsolute)(cacheDirectory) ? cacheDirectory : (0, external_node_path_namespaceObject.join)(context.rootPath, cacheDirectory);
248
- return (0, external_node_path_namespaceObject.join)(context.cachePath);
249
- }
250
- async function getCacheIdentifier(options) {
251
- let identifier = `${process.env.NODE_ENV}${JSON.stringify(options)}`;
252
- const { version: coreVersion } = await Promise.resolve().then(__webpack_require__.t.bind(__webpack_require__, "@babel/core", 23));
253
- const rawPkgJson = await external_node_fs_default().promises.readFile((0, external_node_path_namespaceObject.join)(__dirname, '../compiled/babel-loader/package.json'), 'utf-8');
254
- const loaderVersion = JSON.parse(rawPkgJson).version ?? '';
255
- identifier += `@babel/core@${coreVersion}`;
256
- identifier += `babel-loader@${loaderVersion}`;
257
- return identifier;
258
- }
259
- const getDefaultBabelOptions = (config, context)=>{
260
- const isLegacyDecorators = 'legacy' === config.source.decorators.version;
261
- const options = {
262
- babelrc: false,
263
- configFile: false,
264
- compact: 'production' === config.mode,
265
- plugins: [
266
- [
267
- plugin_require.resolve('@babel/plugin-proposal-decorators'),
268
- 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
+ ] : []
269
144
  ],
270
- // 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:
271
- // see https://babeljs.io/docs/babel-plugin-proposal-decorators#legacy
272
- ...isLegacyDecorators ? [
273
- plugin_require.resolve('@babel/plugin-transform-class-properties')
274
- ] : []
275
- ],
276
- presets: [
277
- // TODO: only apply preset-typescript for ts file (isTSX & allExtensions false)
278
- [
279
- plugin_require.resolve('@babel/preset-typescript'),
280
- DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS
145
+ presets: [
146
+ [
147
+ plugin_require.resolve("@babel/preset-typescript"),
148
+ DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS
149
+ ]
281
150
  ]
282
- ]
283
- };
284
- const { buildCache } = config.performance;
285
- // Rspack does not yet support persistent cache
286
- // so we use babel-loader's cache to improve rebuild performance
287
- if (buildCache && 'rspack' === context.bundlerType) {
288
- const cacheDirectory = getCacheDirectory(context, 'boolean' == typeof buildCache ? void 0 : buildCache.cacheDirectory);
289
- // turn off compression to reduce overhead
290
- options.cacheCompression = false;
291
- options.cacheDirectory = (0, external_node_path_namespaceObject.join)(cacheDirectory, 'babel-loader');
292
- }
293
- return options;
294
- };
295
- const pluginBabel = function() {
296
- let options = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
297
- return {
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, param)=>{
311
- let { CHAIN_ID, environment } = param;
312
- const babelOptions = await getBabelOptions(environment);
313
- const babelLoader = external_node_path_default().resolve(__dirname, '../compiled/babel-loader/index.js');
314
- const { include, exclude } = options;
315
- if (include || exclude) {
316
- const rule = chain.module.rule(BABEL_JS_RULE) // run babel loader before the builtin SWC loader
317
- // https://stackoverflow.com/questions/32234329/what-is-the-loader-order-for-webpack
318
- .after(CHAIN_ID.RULE.JS);
319
- if (include) for (const condition of castArray(include))rule.include.add(condition);
320
- if (exclude) for (const condition of castArray(exclude))rule.exclude.add(condition);
321
- rule.test(SCRIPT_REGEX).use(CHAIN_ID.USE.BABEL).loader(babelLoader).options(babelOptions);
322
- } else {
323
- // already set source.include / exclude in plugin-swc
324
- const rule = chain.module.rule(CHAIN_ID.RULE.JS);
325
- rule.test(SCRIPT_REGEX).use(CHAIN_ID.USE.BABEL).after(CHAIN_ID.USE.SWC).loader(babelLoader).options(babelOptions);
326
- }
327
- }
328
- });
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');
329
157
  }
330
- };
331
- };
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
+ })();
332
181
  var __webpack_export_target__ = exports;
333
- for(var i in __webpack_exports__)__webpack_export_target__[i] = __webpack_exports__[i];
334
- if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
335
- 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
336
185
  });
package/dist/index.js CHANGED
@@ -1,212 +1,131 @@
1
- import { fileURLToPath as __webpack_fileURLToPath__ } from "url";
2
- import { dirname as __webpack_dirname__ } from "path";
3
- import * as __WEBPACK_EXTERNAL_MODULE_node_fs__ from "node:fs";
4
- import * as __WEBPACK_EXTERNAL_MODULE_node_module__ from "node:module";
5
- import * as __WEBPACK_EXTERNAL_MODULE_node_path__ from "node:path";
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";
6
5
  import * as __WEBPACK_EXTERNAL_MODULE_deepmerge__ from "deepmerge";
7
- import * as __WEBPACK_EXTERNAL_MODULE_reduce_configs__ from "reduce-configs";
6
+ import * as __WEBPACK_EXTERNAL_MODULE_reduce_configs_02786df6__ from "reduce-configs";
8
7
  import * as __WEBPACK_EXTERNAL_MODULE_upath__ from "upath";
9
- const BABEL_JS_RULE = 'babel-js';
10
- const castArray = (arr)=>{
11
- if (void 0 === arr) return [];
12
- return Array.isArray(arr) ? arr : [
8
+ let BABEL_JS_RULE = 'babel-js', castArray = (arr)=>void 0 === arr ? [] : Array.isArray(arr) ? arr : [
13
9
  arr
14
- ];
15
- };
16
- const normalizeToPosixPath = (p)=>__WEBPACK_EXTERNAL_MODULE_upath__["default"].normalizeSafe((0, __WEBPACK_EXTERNAL_MODULE_node_path__.normalize)(p || '')).replace(/^([a-zA-Z]+):/, (_, m)=>`/${m.toLowerCase()}`);
17
- // compatible with windows path
18
- const formatPath = (originPath)=>{
19
- if ((0, __WEBPACK_EXTERNAL_MODULE_node_path__.isAbsolute)(originPath)) return originPath.split(__WEBPACK_EXTERNAL_MODULE_node_path__.sep).join('/');
20
- return originPath;
21
- };
22
- const getPluginItemName = (item)=>{
23
- if ('string' == typeof item) return formatPath(item);
24
- if (Array.isArray(item) && 'string' == typeof item[0]) return formatPath(item[0]);
25
- return null;
26
- };
27
- const addPlugins = (plugins, config)=>{
28
- if (config.plugins) config.plugins.push(...plugins);
29
- else config.plugins = plugins;
30
- };
31
- const addPresets = (presets, config)=>{
32
- if (config.presets) config.presets.push(...presets);
33
- else config.presets = presets;
34
- };
35
- 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)=>{
36
15
  if (!config.plugins) return;
37
- const removeList = castArray(plugins);
16
+ let removeList = castArray(plugins);
38
17
  config.plugins = config.plugins.filter((item)=>{
39
- const name = getPluginItemName(item);
40
- if (name) return !removeList.find((removeItem)=>name.includes(removeItem));
41
- return true;
18
+ let name = getPluginItemName(item);
19
+ return !name || !removeList.find((removeItem)=>name.includes(removeItem));
42
20
  });
43
- };
44
- const removePresets = (presets, config)=>{
21
+ }, removePresets = (presets, config)=>{
45
22
  if (!config.presets) return;
46
- const removeList = castArray(presets);
23
+ let removeList = castArray(presets);
47
24
  config.presets = config.presets.filter((item)=>{
48
- const name = getPluginItemName(item);
49
- if (name) return !removeList.find((removeItem)=>name.includes(removeItem));
50
- return true;
25
+ let name = getPluginItemName(item);
26
+ return !name || !removeList.find((removeItem)=>name.includes(removeItem));
51
27
  });
52
- };
53
- const modifyPresetOptions = function(presetName, options) {
54
- let presets = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : [];
28
+ }, modifyPresetOptions = (presetName, options, presets = [])=>{
55
29
  presets.forEach((preset, index)=>{
56
- // 1. ['@babel/preset-env', ...]
57
- if (Array.isArray(preset)) {
58
- if ('string' == typeof preset[0] && normalizeToPosixPath(preset[0]).includes(presetName)) preset[1] = {
59
- ...preset[1] || {},
60
- ...options
61
- };
62
- } else if ('string' == typeof preset && normalizeToPosixPath(preset).includes(presetName)) // 2. '@babel/preset-env'
63
- 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] = [
64
34
  preset,
65
35
  options
66
- ];
36
+ ]);
67
37
  });
68
- };
69
- const getBabelUtils = (config)=>{
70
- const noop = ()=>{};
38
+ }, getBabelUtils = (config)=>{
39
+ let noop = ()=>{};
71
40
  return {
72
41
  addPlugins: (plugins)=>addPlugins(plugins, config),
73
42
  addPresets: (presets)=>addPresets(presets, config),
74
43
  removePlugins: (plugins)=>removePlugins(plugins, config),
75
44
  removePresets: (presets)=>removePresets(presets, config),
76
- // `addIncludes` and `addExcludes` are noop functions by default,
77
- // It can be overridden by `extraBabelUtils`.
78
45
  addIncludes: noop,
79
46
  addExcludes: noop,
80
- // Compat `presetEnvOptions` and `presetReactOptions` in Modern.js
81
47
  modifyPresetEnvOptions: (options)=>modifyPresetOptions('@babel/preset-env', options, config.presets || []),
82
48
  modifyPresetReactOptions: (options)=>modifyPresetOptions('@babel/preset-react', options, config.presets || [])
83
49
  };
84
- };
85
- const applyUserBabelConfig = (defaultOptions, userBabelConfig, extraBabelUtils)=>{
50
+ }, applyUserBabelConfig = (defaultOptions, userBabelConfig, extraBabelUtils)=>{
86
51
  if (userBabelConfig) {
87
- const babelUtils = {
52
+ let babelUtils = {
88
53
  ...getBabelUtils(defaultOptions),
89
54
  ...extraBabelUtils
90
55
  };
91
- return (0, __WEBPACK_EXTERNAL_MODULE_reduce_configs__.reduceConfigsWithContext)({
56
+ return (0, __WEBPACK_EXTERNAL_MODULE_reduce_configs_02786df6__.reduceConfigsWithContext)({
92
57
  initial: defaultOptions,
93
58
  config: userBabelConfig,
94
59
  ctx: babelUtils
95
60
  });
96
61
  }
97
62
  return defaultOptions;
98
- };
99
- const modifyBabelLoaderOptions = (param)=>{
100
- let { chain, CHAIN_ID, modifier } = param;
101
- const ruleIds = [
63
+ }, modifyBabelLoaderOptions = ({ chain, CHAIN_ID, modifier })=>{
64
+ for (let ruleId of [
102
65
  CHAIN_ID.RULE.JS,
103
66
  CHAIN_ID.RULE.JS_DATA_URI,
104
67
  BABEL_JS_RULE
105
- ];
106
- for (const ruleId of ruleIds)if (chain.module.rules.has(ruleId)) {
107
- const rule = chain.module.rule(ruleId);
108
- 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);
109
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
110
78
  };
111
- var plugin_dirname = __webpack_dirname__(__webpack_fileURLToPath__(import.meta.url));
112
- const plugin_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module__.createRequire)(import.meta.url);
113
- const PLUGIN_BABEL_NAME = 'rsbuild:babel';
114
- const SCRIPT_REGEX = /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/;
115
- /**
116
- * The `@babel/preset-typescript` default options.
117
- */ const DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS = {
118
- allowNamespaces: true,
119
- allExtensions: true,
120
- allowDeclareFields: true,
121
- // aligns Babel's behavior with TypeScript's default behavior.
122
- // https://babeljs.io/docs/en/babel-preset-typescript#optimizeconstenums
123
- optimizeConstEnums: true,
124
- isTSX: true
125
- };
126
- function getCacheDirectory(context, cacheDirectory) {
127
- if (cacheDirectory) return (0, __WEBPACK_EXTERNAL_MODULE_node_path__.isAbsolute)(cacheDirectory) ? cacheDirectory : (0, __WEBPACK_EXTERNAL_MODULE_node_path__.join)(context.rootPath, cacheDirectory);
128
- return (0, __WEBPACK_EXTERNAL_MODULE_node_path__.join)(context.cachePath);
129
- }
130
79
  async function getCacheIdentifier(options) {
131
- let identifier = `${process.env.NODE_ENV}${JSON.stringify(options)}`;
132
- const { version: coreVersion } = await import("@babel/core");
133
- 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');
134
- const loaderVersion = JSON.parse(rawPkgJson).version ?? '';
135
- identifier += `@babel/core@${coreVersion}`;
136
- identifier += `babel-loader@${loaderVersion}`;
137
- 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}`;
138
82
  }
139
- const getDefaultBabelOptions = (config, context)=>{
140
- const isLegacyDecorators = 'legacy' === config.source.decorators.version;
141
- const options = {
142
- babelrc: false,
143
- configFile: false,
83
+ let getDefaultBabelOptions = (config, context)=>{
84
+ let isLegacyDecorators = 'legacy' === config.source.decorators.version, options = {
85
+ babelrc: !1,
86
+ configFile: !1,
144
87
  compact: 'production' === config.mode,
145
88
  plugins: [
146
89
  [
147
90
  plugin_require.resolve('@babel/plugin-proposal-decorators'),
148
91
  config.source.decorators
149
92
  ],
150
- // 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:
151
- // see https://babeljs.io/docs/babel-plugin-proposal-decorators#legacy
152
93
  ...isLegacyDecorators ? [
153
94
  plugin_require.resolve('@babel/plugin-transform-class-properties')
154
95
  ] : []
155
96
  ],
156
97
  presets: [
157
- // TODO: only apply preset-typescript for ts file (isTSX & allExtensions false)
158
98
  [
159
- plugin_require.resolve('@babel/preset-typescript'),
99
+ plugin_require.resolve("@babel/preset-typescript"),
160
100
  DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS
161
101
  ]
162
102
  ]
163
- };
164
- const { buildCache } = config.performance;
165
- // Rspack does not yet support persistent cache
166
- // so we use babel-loader's cache to improve rebuild performance
103
+ }, { buildCache = !0 } = config.performance;
167
104
  if (buildCache && 'rspack' === context.bundlerType) {
168
- const cacheDirectory = getCacheDirectory(context, 'boolean' == typeof buildCache ? void 0 : buildCache.cacheDirectory);
169
- // turn off compression to reduce overhead
170
- options.cacheCompression = false;
171
- 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');
172
108
  }
173
109
  return options;
174
- };
175
- const pluginBabel = function() {
176
- let options = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
177
- return {
110
+ }, pluginBabel = (options = {})=>({
178
111
  name: PLUGIN_BABEL_NAME,
179
112
  setup (api) {
180
- const getBabelOptions = async (environment)=>{
181
- const { config } = environment;
182
- const baseOptions = getDefaultBabelOptions(config, api.context);
183
- const mergedOptions = applyUserBabelConfig((0, __WEBPACK_EXTERNAL_MODULE_deepmerge__["default"])({}, baseOptions), options.babelLoaderOptions);
184
- // calculate cacheIdentifier with the merged options
185
- if (mergedOptions.cacheDirectory && !mergedOptions.cacheIdentifier) mergedOptions.cacheIdentifier = await getCacheIdentifier(mergedOptions);
186
- 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;
187
116
  };
188
117
  api.modifyBundlerChain({
189
118
  order: 'pre',
190
- handler: async (chain, param)=>{
191
- let { CHAIN_ID, environment } = param;
192
- const babelOptions = await getBabelOptions(environment);
193
- const babelLoader = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].resolve(plugin_dirname, '../compiled/babel-loader/index.js');
194
- const { include, exclude } = options;
119
+ handler: async (chain, { CHAIN_ID, environment })=>{
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;
195
121
  if (include || exclude) {
196
- const rule = chain.module.rule(BABEL_JS_RULE) // run babel loader before the builtin SWC loader
197
- // https://stackoverflow.com/questions/32234329/what-is-the-loader-order-for-webpack
198
- .after(CHAIN_ID.RULE.JS);
199
- if (include) for (const condition of castArray(include))rule.include.add(condition);
200
- 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);
201
125
  rule.test(SCRIPT_REGEX).use(CHAIN_ID.USE.BABEL).loader(babelLoader).options(babelOptions);
202
- } else {
203
- // already set source.include / exclude in plugin-swc
204
- const rule = chain.module.rule(CHAIN_ID.RULE.JS);
205
- rule.test(SCRIPT_REGEX).use(CHAIN_ID.USE.BABEL).after(CHAIN_ID.USE.SWC).loader(babelLoader).options(babelOptions);
206
- }
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);
207
127
  }
208
128
  });
209
129
  }
210
- };
211
- };
130
+ });
212
131
  export { PLUGIN_BABEL_NAME, getBabelUtils, getDefaultBabelOptions, modifyBabelLoaderOptions, pluginBabel };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-babel",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Babel plugin for Rsbuild",
5
5
  "repository": {
6
6
  "type": "git",
@@ -23,25 +23,26 @@
23
23
  "compiled"
24
24
  ],
25
25
  "dependencies": {
26
- "@babel/core": "^7.25.8",
27
- "@babel/plugin-proposal-decorators": "^7.25.7",
28
- "@babel/plugin-transform-class-properties": "^7.25.7",
29
- "@babel/preset-typescript": "^7.25.7",
26
+ "@babel/core": "^7.26.9",
27
+ "@babel/plugin-proposal-decorators": "^7.25.9",
28
+ "@babel/plugin-transform-class-properties": "^7.25.9",
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.14",
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": {
44
- "@rsbuild/core": "1.x || ^1.0.1-rc.0"
45
+ "@rsbuild/core": "1.x"
45
46
  },
46
47
  "publishConfig": {
47
48
  "access": "public",