@rsbuild/plugin-babel 1.0.1 → 1.0.2
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 +51 -37
- package/compiled/babel-loader/package.json +1 -1
- package/{dist-types → dist}/helper.d.ts +1 -1
- package/dist/index.cjs +313 -268
- package/{dist-types → dist}/index.d.ts +3 -3
- package/dist/index.js +192 -248
- package/{dist-types → dist}/plugin.d.ts +1 -1
- package/package.json +13 -14
- package/dist-types/package.json +0 -1
- /package/{dist-types → dist}/types.d.ts +0 -0
package/dist/index.cjs
CHANGED
|
@@ -1,291 +1,336 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
2
|
+
var __webpack_modules__ = {
|
|
3
|
+
"@babel/core": function(module1) {
|
|
4
|
+
module1.exports = require("@babel/core");
|
|
5
|
+
}
|
|
19
6
|
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
)
|
|
28
|
-
var
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
7
|
+
/************************************************************************/ // The module cache
|
|
8
|
+
var __webpack_module_cache__ = {};
|
|
9
|
+
// The require function
|
|
10
|
+
function __webpack_require__(moduleId) {
|
|
11
|
+
// Check if module is in cache
|
|
12
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
13
|
+
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] = {
|
|
16
|
+
exports: {}
|
|
17
|
+
};
|
|
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;
|
|
22
|
+
}
|
|
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
|
+
});
|
|
87
|
+
};
|
|
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
|
|
38
117
|
});
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
var
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
var
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return Array.isArray(arr) ? arr : [arr];
|
|
56
|
-
};
|
|
57
|
-
var normalizeToPosixPath = (p) => import_upath.default.normalizeSafe((0, import_node_path.normalize)(p || "")).replace(/^([a-zA-Z]+):/, (_, m) => `/${m.toLowerCase()}`);
|
|
58
|
-
var formatPath = (originPath) => {
|
|
59
|
-
if ((0, import_node_path.isAbsolute)(originPath)) {
|
|
60
|
-
return originPath.split(import_node_path.sep).join("/");
|
|
61
|
-
}
|
|
62
|
-
return originPath;
|
|
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
|
+
];
|
|
63
134
|
};
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return formatPath(item[0]);
|
|
70
|
-
}
|
|
71
|
-
return null;
|
|
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;
|
|
72
140
|
};
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
config.plugins = plugins;
|
|
78
|
-
}
|
|
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;
|
|
79
145
|
};
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
config.
|
|
83
|
-
} else {
|
|
84
|
-
config.presets = presets;
|
|
85
|
-
}
|
|
146
|
+
const addPlugins = (plugins, config)=>{
|
|
147
|
+
if (config.plugins) config.plugins.push(...plugins);
|
|
148
|
+
else config.plugins = plugins;
|
|
86
149
|
};
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
const removeList = castArray(plugins);
|
|
92
|
-
config.plugins = config.plugins.filter((item) => {
|
|
93
|
-
const name = getPluginItemName(item);
|
|
94
|
-
if (name) {
|
|
95
|
-
return !removeList.find((removeItem) => name.includes(removeItem));
|
|
96
|
-
}
|
|
97
|
-
return true;
|
|
98
|
-
});
|
|
150
|
+
const addPresets = (presets, config)=>{
|
|
151
|
+
if (config.presets) config.presets.push(...presets);
|
|
152
|
+
else config.presets = presets;
|
|
99
153
|
};
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
return !removeList.find((removeItem) => name.includes(removeItem));
|
|
109
|
-
}
|
|
110
|
-
return true;
|
|
111
|
-
});
|
|
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;
|
|
161
|
+
});
|
|
112
162
|
};
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
} else if (typeof preset === "string" && normalizeToPosixPath(preset).includes(presetName)) {
|
|
124
|
-
presets[index] = [preset, options];
|
|
125
|
-
}
|
|
126
|
-
});
|
|
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;
|
|
170
|
+
});
|
|
127
171
|
};
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
};
|
|
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] = {
|
|
178
|
+
...preset[1] || {},
|
|
179
|
+
...options
|
|
180
|
+
};
|
|
181
|
+
} else if ('string' == typeof preset && normalizeToPosixPath(preset).includes(presetName)) // 2. '@babel/preset-env'
|
|
182
|
+
presets[index] = [
|
|
183
|
+
preset,
|
|
184
|
+
options
|
|
185
|
+
];
|
|
186
|
+
});
|
|
144
187
|
};
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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 || [])
|
|
150
202
|
};
|
|
151
|
-
return (0, import_reduce_configs.reduceConfigsWithContext)({
|
|
152
|
-
initial: defaultOptions,
|
|
153
|
-
config: userBabelConfig,
|
|
154
|
-
ctx: babelUtils
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
return defaultOptions;
|
|
158
203
|
};
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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);
|
|
171
228
|
}
|
|
172
|
-
}
|
|
173
229
|
};
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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
|
|
186
245
|
};
|
|
187
246
|
function getCacheDirectory(context, cacheDirectory) {
|
|
188
|
-
|
|
189
|
-
return (0,
|
|
190
|
-
}
|
|
191
|
-
return (0, import_node_path2.join)(context.cachePath);
|
|
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);
|
|
192
249
|
}
|
|
193
250
|
async function getCacheIdentifier(options) {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
identifier += `@babel/core@${coreVersion}`;
|
|
202
|
-
identifier += `babel-loader@${loaderVersion}`;
|
|
203
|
-
return identifier;
|
|
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;
|
|
204
258
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
if (buildCache && context.bundlerType === "rspack") {
|
|
230
|
-
const cacheDirectory = getCacheDirectory(
|
|
231
|
-
context,
|
|
232
|
-
typeof buildCache === "boolean" ? void 0 : buildCache.cacheDirectory
|
|
233
|
-
);
|
|
234
|
-
options.cacheCompression = false;
|
|
235
|
-
options.cacheDirectory = (0, import_node_path2.join)(cacheDirectory, "babel-loader");
|
|
236
|
-
}
|
|
237
|
-
return options;
|
|
238
|
-
};
|
|
239
|
-
var pluginBabel = (options = {}) => ({
|
|
240
|
-
name: PLUGIN_BABEL_NAME,
|
|
241
|
-
setup(api) {
|
|
242
|
-
const getBabelOptions = async (environment) => {
|
|
243
|
-
const { config } = environment;
|
|
244
|
-
const baseOptions = getDefaultBabelOptions(config, api.context);
|
|
245
|
-
const mergedOptions = applyUserBabelConfig(
|
|
246
|
-
(0, import_deepmerge.default)({}, baseOptions),
|
|
247
|
-
options.babelLoaderOptions
|
|
248
|
-
);
|
|
249
|
-
if (mergedOptions.cacheDirectory && !mergedOptions.cacheIdentifier) {
|
|
250
|
-
mergedOptions.cacheIdentifier = await getCacheIdentifier(mergedOptions);
|
|
251
|
-
}
|
|
252
|
-
return mergedOptions;
|
|
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
|
|
269
|
+
],
|
|
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
|
|
281
|
+
]
|
|
282
|
+
]
|
|
253
283
|
};
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
const
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
);
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
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
|
+
});
|
|
279
329
|
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
PLUGIN_BABEL_NAME,
|
|
287
|
-
getBabelUtils,
|
|
288
|
-
getDefaultBabelOptions,
|
|
289
|
-
modifyBabelLoaderOptions,
|
|
290
|
-
pluginBabel
|
|
330
|
+
};
|
|
331
|
+
};
|
|
332
|
+
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
|
|
291
336
|
});
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { pluginBabel, getDefaultBabelOptions, PLUGIN_BABEL_NAME, } from './plugin';
|
|
2
|
-
export { getBabelUtils, modifyBabelLoaderOptions } from './helper';
|
|
3
|
-
export type { PresetEnvOptions, PresetEnvTargets, PresetEnvBuiltIns, BabelConfigUtils, BabelTransformOptions, PluginBabelOptions, } from './types';
|
|
1
|
+
export { pluginBabel, getDefaultBabelOptions, PLUGIN_BABEL_NAME, } from './plugin.js';
|
|
2
|
+
export { getBabelUtils, modifyBabelLoaderOptions } from './helper.js';
|
|
3
|
+
export type { PresetEnvOptions, PresetEnvTargets, PresetEnvBuiltIns, BabelConfigUtils, BabelTransformOptions, PluginBabelOptions, } from './types.js';
|