@rsbuild/plugin-babel 1.2.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/compiled/babel-loader/index.js +15 -15
- package/dist/index.js +11 -5
- package/dist/types.d.ts +11 -0
- package/package.json +19 -21
- package/dist/index.cjs +0 -191
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
(() => {
|
|
2
2
|
var __webpack_modules__ = {
|
|
3
|
-
|
|
3
|
+
633: (module) => {
|
|
4
4
|
const STRIP_FILENAME_RE = /^[^:]+: /;
|
|
5
5
|
const format = (err) => {
|
|
6
6
|
if (err instanceof SyntaxError) {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
}
|
|
27
27
|
module.exports = LoaderError;
|
|
28
28
|
},
|
|
29
|
-
|
|
29
|
+
261: (module, __unused_webpack_exports, __nccwpck_require__) => {
|
|
30
30
|
const os = __nccwpck_require__(857);
|
|
31
31
|
const path = __nccwpck_require__(928);
|
|
32
32
|
const zlib = __nccwpck_require__(106);
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
const { readFile, writeFile, mkdir } = __nccwpck_require__(943);
|
|
35
35
|
const { sync: findUpSync } = __nccwpck_require__(48);
|
|
36
36
|
const { env } = process;
|
|
37
|
-
const transform = __nccwpck_require__(
|
|
38
|
-
const serialize = __nccwpck_require__(
|
|
37
|
+
const transform = __nccwpck_require__(555);
|
|
38
|
+
const serialize = __nccwpck_require__(9);
|
|
39
39
|
let defaultCacheDirectory = null;
|
|
40
40
|
const gunzip = promisify(zlib.gunzip);
|
|
41
41
|
const gzip = promisify(zlib.gzip);
|
|
@@ -174,7 +174,7 @@
|
|
|
174
174
|
return os.tmpdir();
|
|
175
175
|
}
|
|
176
176
|
},
|
|
177
|
-
|
|
177
|
+
811: (module, __unused_webpack_exports, __nccwpck_require__) => {
|
|
178
178
|
let babel;
|
|
179
179
|
try {
|
|
180
180
|
babel = __nccwpck_require__(571);
|
|
@@ -193,10 +193,10 @@
|
|
|
193
193
|
);
|
|
194
194
|
}
|
|
195
195
|
const { version } = __nccwpck_require__(344);
|
|
196
|
-
const cache = __nccwpck_require__(
|
|
197
|
-
const transform = __nccwpck_require__(
|
|
198
|
-
const injectCaller = __nccwpck_require__(
|
|
199
|
-
const schema = __nccwpck_require__(
|
|
196
|
+
const cache = __nccwpck_require__(261);
|
|
197
|
+
const transform = __nccwpck_require__(555);
|
|
198
|
+
const injectCaller = __nccwpck_require__(161);
|
|
199
|
+
const schema = __nccwpck_require__(814);
|
|
200
200
|
const { isAbsolute } = __nccwpck_require__(928);
|
|
201
201
|
const { promisify } = __nccwpck_require__(23);
|
|
202
202
|
function subscribe(subscriber, metadata, context) {
|
|
@@ -383,7 +383,7 @@
|
|
|
383
383
|
return [source, inputSourceMap];
|
|
384
384
|
}
|
|
385
385
|
},
|
|
386
|
-
|
|
386
|
+
161: (module) => {
|
|
387
387
|
module.exports = function injectCaller(opts, target) {
|
|
388
388
|
return {
|
|
389
389
|
...opts,
|
|
@@ -400,7 +400,7 @@
|
|
|
400
400
|
};
|
|
401
401
|
};
|
|
402
402
|
},
|
|
403
|
-
|
|
403
|
+
9: (module) => {
|
|
404
404
|
var objToString = Object.prototype.toString;
|
|
405
405
|
var objKeys = Object.getOwnPropertyNames;
|
|
406
406
|
function serialize(val, isArrayProp) {
|
|
@@ -466,10 +466,10 @@
|
|
|
466
466
|
}
|
|
467
467
|
};
|
|
468
468
|
},
|
|
469
|
-
|
|
469
|
+
555: (module, __unused_webpack_exports, __nccwpck_require__) => {
|
|
470
470
|
const babel = __nccwpck_require__(571);
|
|
471
471
|
const { promisify } = __nccwpck_require__(23);
|
|
472
|
-
const LoaderError = __nccwpck_require__(
|
|
472
|
+
const LoaderError = __nccwpck_require__(633);
|
|
473
473
|
const babelTransform = babel.transformAsync ?? promisify(babel.transform);
|
|
474
474
|
module.exports = async function transform(source, options) {
|
|
475
475
|
let result;
|
|
@@ -820,7 +820,7 @@
|
|
|
820
820
|
"use strict";
|
|
821
821
|
module.exports = require("zlib");
|
|
822
822
|
},
|
|
823
|
-
|
|
823
|
+
814: (module) => {
|
|
824
824
|
"use strict";
|
|
825
825
|
module.exports = JSON.parse(
|
|
826
826
|
'{"title":"Babel Loader options","type":"object","properties":{"cacheDirectory":{"anyOf":[{"type":"boolean"},{"type":"string"}],"default":false},"cacheIdentifier":{"type":"string"},"cacheCompression":{"type":"boolean","default":true},"customize":{"anyOf":[{"type":"null"},{"type":"string"}],"default":null},"metadataSubscribers":{"type":"array"}},"additionalProperties":true}',
|
|
@@ -849,6 +849,6 @@
|
|
|
849
849
|
}
|
|
850
850
|
if (typeof __nccwpck_require__ !== "undefined")
|
|
851
851
|
__nccwpck_require__.ab = __dirname + "/";
|
|
852
|
-
var __webpack_exports__ = __nccwpck_require__(
|
|
852
|
+
var __webpack_exports__ = __nccwpck_require__(811);
|
|
853
853
|
module.exports = __webpack_exports__;
|
|
854
854
|
})();
|
package/dist/index.js
CHANGED
|
@@ -59,7 +59,11 @@ let BABEL_JS_RULE = 'babel-js', BABEL_JS_RULE_REGEXP = /^babel-js(?:-\d+)?$/, is
|
|
|
59
59
|
chain.module.rules.get(CHAIN_ID.RULE.JS_DATA_URI),
|
|
60
60
|
...Object.keys(chain.module.rules.entries()).filter(isBabelRuleId).map((id)=>chain.module.rules.get(id))
|
|
61
61
|
].filter(Boolean))rule.uses.has(CHAIN_ID.USE.BABEL) && rule.use(CHAIN_ID.USE.BABEL).tap(modifier);
|
|
62
|
-
}, plugin_dirname = node_path.dirname(fileURLToPath(import.meta.url)), plugin_require = createRequire(import.meta.url), PLUGIN_BABEL_NAME = 'rsbuild:babel', SCRIPT_REGEX = /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)
|
|
62
|
+
}, plugin_dirname = node_path.dirname(fileURLToPath(import.meta.url)), plugin_require = createRequire(import.meta.url), PLUGIN_BABEL_NAME = 'rsbuild:babel', SCRIPT_REGEX = /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/;
|
|
63
|
+
function assertCoreVersion(version) {
|
|
64
|
+
if ('1' === version.split('.')[0]) throw Error('"@rsbuild/plugin-babel" v2 requires "@rsbuild/core" >= 2.0. Please upgrade "@rsbuild/core" or use "@rsbuild/plugin-babel" v1.');
|
|
65
|
+
}
|
|
66
|
+
let DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS = {
|
|
63
67
|
allowNamespaces: !0,
|
|
64
68
|
allExtensions: !0,
|
|
65
69
|
allowDeclareFields: !0,
|
|
@@ -107,6 +111,7 @@ function getDefaultBabelOptions(config, context) {
|
|
|
107
111
|
let pluginBabel = (options = {})=>({
|
|
108
112
|
name: PLUGIN_BABEL_NAME,
|
|
109
113
|
setup (api) {
|
|
114
|
+
assertCoreVersion(api.context.version);
|
|
110
115
|
let getBabelOptions = async (environment)=>{
|
|
111
116
|
let { config } = environment, mergedOptions = ((defaultOptions, userBabelConfig)=>{
|
|
112
117
|
if (userBabelConfig) {
|
|
@@ -127,7 +132,7 @@ let pluginBabel = (options = {})=>({
|
|
|
127
132
|
api.modifyBundlerChain({
|
|
128
133
|
order: 'pre',
|
|
129
134
|
handler: async (chain, { CHAIN_ID, environment })=>{
|
|
130
|
-
let babelOptions = await getBabelOptions(environment), babelLoader = node_path.resolve(plugin_dirname, '../compiled/babel-loader/index.js'), { include, exclude } = options;
|
|
135
|
+
let babelOptions = await getBabelOptions(environment), babelLoader = node_path.resolve(plugin_dirname, '../compiled/babel-loader/index.js'), { include, exclude, parallel = !1 } = options;
|
|
131
136
|
if (include || exclude) {
|
|
132
137
|
let rule = chain.module.rule(((chain)=>{
|
|
133
138
|
let id = BABEL_JS_RULE, index = 0;
|
|
@@ -136,10 +141,11 @@ let pluginBabel = (options = {})=>({
|
|
|
136
141
|
})(chain)).after(CHAIN_ID.RULE.JS);
|
|
137
142
|
if (include) for (let condition of castArray(include))rule.include.add(condition);
|
|
138
143
|
if (exclude) for (let condition of castArray(exclude))rule.exclude.add(condition);
|
|
139
|
-
rule.test(SCRIPT_REGEX).use(CHAIN_ID.USE.BABEL).loader(babelLoader).options(babelOptions);
|
|
144
|
+
let loader = rule.test(SCRIPT_REGEX).use(CHAIN_ID.USE.BABEL).loader(babelLoader).options(babelOptions);
|
|
145
|
+
parallel && loader.parallel(!0);
|
|
140
146
|
} else {
|
|
141
|
-
let
|
|
142
|
-
|
|
147
|
+
let loader = chain.module.rule(CHAIN_ID.RULE.JS).test(SCRIPT_REGEX).oneOfs.get(CHAIN_ID.ONE_OF.JS_MAIN).use(CHAIN_ID.USE.BABEL).after(CHAIN_ID.USE.SWC).loader(babelLoader).options(babelOptions);
|
|
148
|
+
parallel && loader.parallel(!0);
|
|
143
149
|
}
|
|
144
150
|
}
|
|
145
151
|
});
|
package/dist/types.d.ts
CHANGED
|
@@ -84,4 +84,15 @@ export type PluginBabelOptions = {
|
|
|
84
84
|
* Options passed to `babel-loader`.
|
|
85
85
|
* @see https://github.com/babel/babel-loader
|
|
86
86
|
*/ babelLoaderOptions?: ConfigChainWithContext<BabelLoaderOptions, BabelConfigUtils>;
|
|
87
|
+
/**
|
|
88
|
+
* Whether to run Babel transformations in parallel using worker threads. When
|
|
89
|
+
* enabled, JavaScript modules are processed across multiple worker threads,
|
|
90
|
+
* reducing pressure on the main thread and improving overall build performance
|
|
91
|
+
* when compiling large numbers of modules.
|
|
92
|
+
*
|
|
93
|
+
* Options transferred to worker threads must comply with the HTML structured clone
|
|
94
|
+
* algorithm. For example, functions cannot be passed as options.
|
|
95
|
+
* @see https://nodejs.org/api/worker_threads.html#portpostmessagevalue-transferlist
|
|
96
|
+
* @default false
|
|
97
|
+
*/ parallel?: boolean;
|
|
87
98
|
};
|
package/package.json
CHANGED
|
@@ -1,56 +1,54 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/plugin-babel",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Babel plugin for Rsbuild",
|
|
5
|
+
"license": "MIT",
|
|
5
6
|
"repository": {
|
|
6
7
|
"type": "git",
|
|
7
8
|
"url": "https://github.com/web-infra-dev/rsbuild",
|
|
8
9
|
"directory": "packages/plugin-babel"
|
|
9
10
|
},
|
|
10
|
-
"
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"compiled"
|
|
14
|
+
],
|
|
11
15
|
"type": "module",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
12
17
|
"exports": {
|
|
13
18
|
".": {
|
|
14
19
|
"types": "./dist/index.d.ts",
|
|
15
|
-
"
|
|
16
|
-
"require": "./dist/index.cjs"
|
|
20
|
+
"default": "./dist/index.js"
|
|
17
21
|
}
|
|
18
22
|
},
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
],
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public",
|
|
25
|
+
"registry": "https://registry.npmjs.org/"
|
|
26
|
+
},
|
|
24
27
|
"dependencies": {
|
|
25
|
-
"@babel/core": "^7.29.
|
|
26
|
-
"@babel/plugin-proposal-decorators": "^7.29.
|
|
28
|
+
"@babel/core": "^7.29.7",
|
|
29
|
+
"@babel/plugin-proposal-decorators": "^7.29.7",
|
|
27
30
|
"@babel/plugin-transform-class-properties": "^7.29.7",
|
|
28
31
|
"@babel/preset-typescript": "^7.29.7",
|
|
29
32
|
"@types/babel__core": "^7.20.5",
|
|
30
33
|
"reduce-configs": "^1.1.2"
|
|
31
34
|
},
|
|
32
35
|
"devDependencies": {
|
|
33
|
-
"@
|
|
34
|
-
"@
|
|
35
|
-
"@types/node": "^24.12.4",
|
|
36
|
+
"@rslib/core": "0.22.1",
|
|
37
|
+
"@types/node": "^24.13.2",
|
|
36
38
|
"babel-loader": "10.1.1",
|
|
37
|
-
"prebundle": "1.6.
|
|
39
|
+
"prebundle": "1.6.5",
|
|
38
40
|
"typescript": "^6.0.3",
|
|
39
|
-
"@rsbuild/core": "2.0.
|
|
41
|
+
"@rsbuild/core": "2.0.15",
|
|
40
42
|
"@scripts/test-helper": "1.0.0"
|
|
41
43
|
},
|
|
42
44
|
"peerDependencies": {
|
|
43
|
-
"@rsbuild/core": "^
|
|
45
|
+
"@rsbuild/core": "^2.0.0"
|
|
44
46
|
},
|
|
45
47
|
"peerDependenciesMeta": {
|
|
46
48
|
"@rsbuild/core": {
|
|
47
49
|
"optional": true
|
|
48
50
|
}
|
|
49
51
|
},
|
|
50
|
-
"publishConfig": {
|
|
51
|
-
"access": "public",
|
|
52
|
-
"registry": "https://registry.npmjs.org/"
|
|
53
|
-
},
|
|
54
52
|
"scripts": {
|
|
55
53
|
"build": "rslib",
|
|
56
54
|
"dev": "rslib -w",
|
package/dist/index.cjs
DELETED
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const __rslib_import_meta_url__ = "u" < typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
|
|
3
|
-
var __webpack_require__ = {};
|
|
4
|
-
__webpack_require__.n = (module)=>{
|
|
5
|
-
var getter = module && module.__esModule ? ()=>module.default : ()=>module;
|
|
6
|
-
return __webpack_require__.d(getter, {
|
|
7
|
-
a: getter
|
|
8
|
-
}), getter;
|
|
9
|
-
}, __webpack_require__.d = (exports1, getters, values)=>{
|
|
10
|
-
var define = (defs, kind)=>{
|
|
11
|
-
for(var key in defs)__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key) && Object.defineProperty(exports1, key, {
|
|
12
|
-
enumerable: !0,
|
|
13
|
-
[kind]: defs[key]
|
|
14
|
-
});
|
|
15
|
-
};
|
|
16
|
-
define(getters, "get"), define(values, "value");
|
|
17
|
-
}, __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop), __webpack_require__.r = (exports1)=>{
|
|
18
|
-
"u" > typeof Symbol && Symbol.toStringTag && Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
19
|
-
value: 'Module'
|
|
20
|
-
}), Object.defineProperty(exports1, '__esModule', {
|
|
21
|
-
value: !0
|
|
22
|
-
});
|
|
23
|
-
};
|
|
24
|
-
var __webpack_exports__ = {};
|
|
25
|
-
__webpack_require__.r(__webpack_exports__), __webpack_require__.d(__webpack_exports__, {
|
|
26
|
-
PLUGIN_BABEL_NAME: ()=>PLUGIN_BABEL_NAME,
|
|
27
|
-
getBabelUtils: ()=>getBabelUtils,
|
|
28
|
-
getDefaultBabelOptions: ()=>getDefaultBabelOptions,
|
|
29
|
-
modifyBabelLoaderOptions: ()=>modifyBabelLoaderOptions,
|
|
30
|
-
pluginBabel: ()=>pluginBabel
|
|
31
|
-
});
|
|
32
|
-
const external_node_path_namespaceObject = require("node:path");
|
|
33
|
-
var external_node_path_default = __webpack_require__.n(external_node_path_namespaceObject);
|
|
34
|
-
const external_reduce_configs_namespaceObject = require("reduce-configs"), BABEL_JS_RULE = 'babel-js', BABEL_JS_RULE_REGEXP = /^babel-js(?:-\d+)?$/, getBabelRuleId = (chain)=>{
|
|
35
|
-
let id = BABEL_JS_RULE, index = 0;
|
|
36
|
-
for(; chain.module.rules.has(id);)id = `${BABEL_JS_RULE}-${++index}`;
|
|
37
|
-
return id;
|
|
38
|
-
}, isBabelRuleId = (id)=>BABEL_JS_RULE_REGEXP.test(id), getBabelRules = (chain)=>Object.keys(chain.module.rules.entries()).filter(isBabelRuleId).map((id)=>chain.module.rules.get(id)), castArray = (arr)=>void 0 === arr ? [] : Array.isArray(arr) ? arr : [
|
|
39
|
-
arr
|
|
40
|
-
], normalizeToPosixPath = (p)=>(0, external_node_path_namespaceObject.normalize)(p || '').replace(/\\/g, '/').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)=>{
|
|
41
|
-
config.plugins ? config.plugins.push(...plugins) : config.plugins = plugins;
|
|
42
|
-
}, addPresets = (presets, config)=>{
|
|
43
|
-
config.presets ? config.presets.push(...presets) : config.presets = presets;
|
|
44
|
-
}, removePlugins = (plugins, config)=>{
|
|
45
|
-
if (!config.plugins) return;
|
|
46
|
-
let removeList = castArray(plugins);
|
|
47
|
-
config.plugins = config.plugins.filter((item)=>{
|
|
48
|
-
let name = getPluginItemName(item);
|
|
49
|
-
return !name || !removeList.find((removeItem)=>name.includes(removeItem));
|
|
50
|
-
});
|
|
51
|
-
}, removePresets = (presets, config)=>{
|
|
52
|
-
if (!config.presets) return;
|
|
53
|
-
let removeList = castArray(presets);
|
|
54
|
-
config.presets = config.presets.filter((item)=>{
|
|
55
|
-
let name = getPluginItemName(item);
|
|
56
|
-
return !name || !removeList.find((removeItem)=>name.includes(removeItem));
|
|
57
|
-
});
|
|
58
|
-
}, modifyPresetOptions = (presetName, options, presets = [])=>{
|
|
59
|
-
presets.forEach((preset, index)=>{
|
|
60
|
-
Array.isArray(preset) ? 'string' == typeof preset[0] && normalizeToPosixPath(preset[0]).includes(presetName) && (preset[1] = {
|
|
61
|
-
...preset[1] || {},
|
|
62
|
-
...options
|
|
63
|
-
}) : 'string' == typeof preset && normalizeToPosixPath(preset).includes(presetName) && (presets[index] = [
|
|
64
|
-
preset,
|
|
65
|
-
options
|
|
66
|
-
]);
|
|
67
|
-
});
|
|
68
|
-
}, getBabelUtils = (config)=>{
|
|
69
|
-
let noop = ()=>{};
|
|
70
|
-
return {
|
|
71
|
-
addPlugins: (plugins)=>{
|
|
72
|
-
addPlugins(plugins, config);
|
|
73
|
-
},
|
|
74
|
-
addPresets: (presets)=>{
|
|
75
|
-
addPresets(presets, config);
|
|
76
|
-
},
|
|
77
|
-
removePlugins: (plugins)=>{
|
|
78
|
-
removePlugins(plugins, config);
|
|
79
|
-
},
|
|
80
|
-
removePresets: (presets)=>{
|
|
81
|
-
removePresets(presets, config);
|
|
82
|
-
},
|
|
83
|
-
addIncludes: noop,
|
|
84
|
-
addExcludes: noop,
|
|
85
|
-
modifyPresetEnvOptions: (options)=>{
|
|
86
|
-
modifyPresetOptions('@babel/preset-env', options, config.presets || []);
|
|
87
|
-
},
|
|
88
|
-
modifyPresetReactOptions: (options)=>{
|
|
89
|
-
modifyPresetOptions('@babel/preset-react', options, config.presets || []);
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
}, applyUserBabelConfig = (defaultOptions, userBabelConfig, extraBabelUtils)=>{
|
|
93
|
-
if (userBabelConfig) {
|
|
94
|
-
let babelUtils = {
|
|
95
|
-
...getBabelUtils(defaultOptions),
|
|
96
|
-
...extraBabelUtils
|
|
97
|
-
};
|
|
98
|
-
return (0, external_reduce_configs_namespaceObject.reduceConfigsWithContext)({
|
|
99
|
-
initial: defaultOptions,
|
|
100
|
-
config: userBabelConfig,
|
|
101
|
-
ctx: babelUtils
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
return defaultOptions;
|
|
105
|
-
}, modifyBabelLoaderOptions = ({ chain, CHAIN_ID, modifier })=>{
|
|
106
|
-
for (let rule of [
|
|
107
|
-
chain.module.rules.get(CHAIN_ID.RULE.JS).oneOfs.get(CHAIN_ID.ONE_OF.JS_MAIN),
|
|
108
|
-
chain.module.rules.get(CHAIN_ID.RULE.JS_DATA_URI),
|
|
109
|
-
...getBabelRules(chain)
|
|
110
|
-
].filter(Boolean))rule.uses.has(CHAIN_ID.USE.BABEL) && rule.use(CHAIN_ID.USE.BABEL).tap(modifier);
|
|
111
|
-
}, external_node_fs_namespaceObject = require("node:fs");
|
|
112
|
-
var external_node_fs_default = __webpack_require__.n(external_node_fs_namespaceObject);
|
|
113
|
-
const external_node_module_namespaceObject = require("node:module"), external_node_url_namespaceObject = require("node:url"), 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 = {
|
|
114
|
-
allowNamespaces: !0,
|
|
115
|
-
allExtensions: !0,
|
|
116
|
-
allowDeclareFields: !0,
|
|
117
|
-
optimizeConstEnums: !0,
|
|
118
|
-
isTSX: !0
|
|
119
|
-
};
|
|
120
|
-
function getCacheDirectory(context, cacheDirectory) {
|
|
121
|
-
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);
|
|
122
|
-
}
|
|
123
|
-
async function getCacheIdentifier(options) {
|
|
124
|
-
let identifier = `${process.env.NODE_ENV}${JSON.stringify(options)}`, { version: coreVersion } = await import("@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 ?? '';
|
|
125
|
-
return identifier + `@babel/core@${coreVersion}babel-loader@${loaderVersion}`;
|
|
126
|
-
}
|
|
127
|
-
function getDefaultBabelOptions(config, context) {
|
|
128
|
-
let isLegacyDecorators = 'legacy' === config.source.decorators.version, options = {
|
|
129
|
-
babelrc: !1,
|
|
130
|
-
configFile: !1,
|
|
131
|
-
compact: 'production' === config.mode,
|
|
132
|
-
plugins: [
|
|
133
|
-
[
|
|
134
|
-
plugin_require.resolve('@babel/plugin-proposal-decorators'),
|
|
135
|
-
{
|
|
136
|
-
...config.source.decorators
|
|
137
|
-
}
|
|
138
|
-
],
|
|
139
|
-
...isLegacyDecorators ? [
|
|
140
|
-
plugin_require.resolve('@babel/plugin-transform-class-properties')
|
|
141
|
-
] : []
|
|
142
|
-
],
|
|
143
|
-
presets: [
|
|
144
|
-
[
|
|
145
|
-
plugin_require.resolve("@babel/preset-typescript"),
|
|
146
|
-
{
|
|
147
|
-
...DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS
|
|
148
|
-
}
|
|
149
|
-
]
|
|
150
|
-
]
|
|
151
|
-
}, { buildCache = !0 } = config.performance;
|
|
152
|
-
if (buildCache && 'rspack' === context.bundlerType) {
|
|
153
|
-
let cacheDirectory = getCacheDirectory(context, 'boolean' == typeof buildCache ? void 0 : buildCache.cacheDirectory);
|
|
154
|
-
options.cacheCompression = !1, options.cacheDirectory = (0, external_node_path_namespaceObject.join)(cacheDirectory, 'babel-loader');
|
|
155
|
-
}
|
|
156
|
-
return options;
|
|
157
|
-
}
|
|
158
|
-
const pluginBabel = (options = {})=>({
|
|
159
|
-
name: PLUGIN_BABEL_NAME,
|
|
160
|
-
setup (api) {
|
|
161
|
-
let getBabelOptions = async (environment)=>{
|
|
162
|
-
let { config } = environment, mergedOptions = applyUserBabelConfig(getDefaultBabelOptions(config, api.context), options.babelLoaderOptions);
|
|
163
|
-
return mergedOptions.cacheDirectory && !mergedOptions.cacheIdentifier && (mergedOptions.cacheIdentifier = await getCacheIdentifier(mergedOptions)), mergedOptions;
|
|
164
|
-
};
|
|
165
|
-
api.modifyBundlerChain({
|
|
166
|
-
order: 'pre',
|
|
167
|
-
handler: async (chain, { CHAIN_ID, environment })=>{
|
|
168
|
-
let babelOptions = await getBabelOptions(environment), babelLoader = external_node_path_default().resolve(plugin_dirname, '../compiled/babel-loader/index.js'), { include, exclude } = options;
|
|
169
|
-
if (include || exclude) {
|
|
170
|
-
let rule = chain.module.rule(getBabelRuleId(chain)).after(CHAIN_ID.RULE.JS);
|
|
171
|
-
if (include) for (let condition of castArray(include))rule.include.add(condition);
|
|
172
|
-
if (exclude) for (let condition of castArray(exclude))rule.exclude.add(condition);
|
|
173
|
-
rule.test(SCRIPT_REGEX).use(CHAIN_ID.USE.BABEL).loader(babelLoader).options(babelOptions);
|
|
174
|
-
} else {
|
|
175
|
-
let isV1 = api.context.version.startsWith('1.'), jsRule = chain.module.rule(CHAIN_ID.RULE.JS).test(SCRIPT_REGEX);
|
|
176
|
-
(isV1 ? jsRule : jsRule.oneOfs.get(CHAIN_ID.ONE_OF.JS_MAIN)).use(CHAIN_ID.USE.BABEL).after(CHAIN_ID.USE.SWC).loader(babelLoader).options(babelOptions);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
for(var __rspack_i in exports.PLUGIN_BABEL_NAME = __webpack_exports__.PLUGIN_BABEL_NAME, exports.getBabelUtils = __webpack_exports__.getBabelUtils, exports.getDefaultBabelOptions = __webpack_exports__.getDefaultBabelOptions, exports.modifyBabelLoaderOptions = __webpack_exports__.modifyBabelLoaderOptions, exports.pluginBabel = __webpack_exports__.pluginBabel, __webpack_exports__)-1 === [
|
|
183
|
-
"PLUGIN_BABEL_NAME",
|
|
184
|
-
"getBabelUtils",
|
|
185
|
-
"getDefaultBabelOptions",
|
|
186
|
-
"modifyBabelLoaderOptions",
|
|
187
|
-
"pluginBabel"
|
|
188
|
-
].indexOf(__rspack_i) && (exports[__rspack_i] = __webpack_exports__[__rspack_i]);
|
|
189
|
-
Object.defineProperty(exports, '__esModule', {
|
|
190
|
-
value: !0
|
|
191
|
-
});
|