@rsbuild/plugin-babel 1.0.3 → 1.0.5
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 +11 -11
- package/compiled/babel-loader/index.js +488 -167
- package/compiled/babel-loader/package.json +1 -1
- package/dist/index.cjs +162 -313
- package/dist/index.js +60 -134
- package/package.json +10 -9
- package/compiled/babel-loader/672.index.js +0 -550
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"babel-loader","author":"Luis Couto <hello@luiscouto.pt>","version":"
|
|
1
|
+
{"name":"babel-loader","author":"Luis Couto <hello@luiscouto.pt>","version":"10.0.0","license":"MIT","types":"index.d.ts","type":"commonjs"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,334 +1,183 @@
|
|
|
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(
|
|
4
|
-
|
|
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
|
-
|
|
15
|
-
var module1 = __webpack_module_cache__[moduleId] = {
|
|
11
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
16
12
|
exports: {}
|
|
17
13
|
};
|
|
18
|
-
|
|
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
|
-
|
|
24
|
-
(()=>
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
|
117
|
-
});
|
|
118
|
-
const external_node_fs_namespaceObject = require("node:fs");
|
|
119
|
-
var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
|
|
120
|
-
const external_node_module_namespaceObject = require("node:module");
|
|
121
|
-
const external_node_path_namespaceObject = require("node:path");
|
|
122
|
-
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
123
|
-
const external_node_url_namespaceObject = require("node:url");
|
|
124
|
-
const external_deepmerge_namespaceObject = require("deepmerge");
|
|
125
|
-
var external_deepmerge_default = /*#__PURE__*/ __webpack_require__.n(external_deepmerge_namespaceObject);
|
|
126
|
-
const external_reduce_configs_namespaceObject = require("reduce-configs");
|
|
127
|
-
const external_upath_namespaceObject = require("upath");
|
|
128
|
-
var external_upath_default = /*#__PURE__*/ __webpack_require__.n(external_upath_namespaceObject);
|
|
129
|
-
const BABEL_JS_RULE = 'babel-js';
|
|
130
|
-
const castArray = (arr)=>{
|
|
131
|
-
if (void 0 === arr) return [];
|
|
132
|
-
return Array.isArray(arr) ? arr : [
|
|
133
|
-
arr
|
|
134
|
-
];
|
|
135
|
-
};
|
|
136
|
-
const normalizeToPosixPath = (p)=>external_upath_default().normalizeSafe((0, external_node_path_namespaceObject.normalize)(p || '')).replace(/^([a-zA-Z]+):/, (_, m)=>`/${m.toLowerCase()}`);
|
|
137
|
-
// compatible with Windows path
|
|
138
|
-
const formatPath = (originPath)=>{
|
|
139
|
-
if ((0, external_node_path_namespaceObject.isAbsolute)(originPath)) return originPath.split(external_node_path_namespaceObject.sep).join('/');
|
|
140
|
-
return originPath;
|
|
141
|
-
};
|
|
142
|
-
const getPluginItemName = (item)=>{
|
|
143
|
-
if ('string' == typeof item) return formatPath(item);
|
|
144
|
-
if (Array.isArray(item) && 'string' == typeof item[0]) return formatPath(item[0]);
|
|
145
|
-
return null;
|
|
146
|
-
};
|
|
147
|
-
const addPlugins = (plugins, config)=>{
|
|
148
|
-
if (config.plugins) config.plugins.push(...plugins);
|
|
149
|
-
else config.plugins = plugins;
|
|
150
|
-
};
|
|
151
|
-
const addPresets = (presets, config)=>{
|
|
152
|
-
if (config.presets) config.presets.push(...presets);
|
|
153
|
-
else config.presets = presets;
|
|
154
|
-
};
|
|
155
|
-
const removePlugins = (plugins, config)=>{
|
|
156
|
-
if (!config.plugins) return;
|
|
157
|
-
const removeList = castArray(plugins);
|
|
158
|
-
config.plugins = config.plugins.filter((item)=>{
|
|
159
|
-
const name = getPluginItemName(item);
|
|
160
|
-
if (name) return !removeList.find((removeItem)=>name.includes(removeItem));
|
|
161
|
-
return true;
|
|
16
|
+
__webpack_require__.n = (module)=>{
|
|
17
|
+
var getter = module && module.__esModule ? ()=>module.default : ()=>module;
|
|
18
|
+
return __webpack_require__.d(getter, {
|
|
19
|
+
a: getter
|
|
20
|
+
}), getter;
|
|
21
|
+
}, __webpack_require__.d = (exports1, definition)=>{
|
|
22
|
+
for(var key in definition)__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key) && Object.defineProperty(exports1, key, {
|
|
23
|
+
enumerable: !0,
|
|
24
|
+
get: definition[key]
|
|
162
25
|
});
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
const name = getPluginItemName(item);
|
|
169
|
-
if (name) return !removeList.find((removeItem)=>name.includes(removeItem));
|
|
170
|
-
return true;
|
|
26
|
+
}, __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop), __webpack_require__.r = (exports1)=>{
|
|
27
|
+
'undefined' != typeof Symbol && Symbol.toStringTag && Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
28
|
+
value: 'Module'
|
|
29
|
+
}), Object.defineProperty(exports1, '__esModule', {
|
|
30
|
+
value: !0
|
|
171
31
|
});
|
|
172
32
|
};
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
33
|
+
var __webpack_exports__ = {};
|
|
34
|
+
for(var __webpack_i__ in (()=>{
|
|
35
|
+
__webpack_require__.r(__webpack_exports__), __webpack_require__.d(__webpack_exports__, {
|
|
36
|
+
getBabelUtils: ()=>getBabelUtils,
|
|
37
|
+
getDefaultBabelOptions: ()=>getDefaultBabelOptions,
|
|
38
|
+
pluginBabel: ()=>pluginBabel,
|
|
39
|
+
modifyBabelLoaderOptions: ()=>modifyBabelLoaderOptions,
|
|
40
|
+
PLUGIN_BABEL_NAME: ()=>PLUGIN_BABEL_NAME
|
|
41
|
+
});
|
|
42
|
+
let external_node_fs_namespaceObject = require("node:fs");
|
|
43
|
+
var external_node_fs_default = __webpack_require__.n(external_node_fs_namespaceObject);
|
|
44
|
+
let external_node_module_namespaceObject = require("node:module"), external_node_path_namespaceObject = require("node:path");
|
|
45
|
+
var external_node_path_default = __webpack_require__.n(external_node_path_namespaceObject);
|
|
46
|
+
let external_node_url_namespaceObject = require("node:url"), external_deepmerge_namespaceObject = require("deepmerge");
|
|
47
|
+
var external_deepmerge_default = __webpack_require__.n(external_deepmerge_namespaceObject);
|
|
48
|
+
let external_reduce_configs_namespaceObject = require("reduce-configs"), external_upath_namespaceObject = require("upath");
|
|
49
|
+
var external_upath_default = __webpack_require__.n(external_upath_namespaceObject);
|
|
50
|
+
let BABEL_JS_RULE = 'babel-js', castArray = (arr)=>void 0 === arr ? [] : Array.isArray(arr) ? arr : [
|
|
51
|
+
arr
|
|
52
|
+
], 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)=>{
|
|
53
|
+
config.plugins ? config.plugins.push(...plugins) : config.plugins = plugins;
|
|
54
|
+
}, addPresets = (presets, config)=>{
|
|
55
|
+
config.presets ? config.presets.push(...presets) : config.presets = presets;
|
|
56
|
+
}, removePlugins = (plugins, config)=>{
|
|
57
|
+
if (!config.plugins) return;
|
|
58
|
+
let removeList = castArray(plugins);
|
|
59
|
+
config.plugins = config.plugins.filter((item)=>{
|
|
60
|
+
let name = getPluginItemName(item);
|
|
61
|
+
return !name || !removeList.find((removeItem)=>name.includes(removeItem));
|
|
62
|
+
});
|
|
63
|
+
}, removePresets = (presets, config)=>{
|
|
64
|
+
if (!config.presets) return;
|
|
65
|
+
let removeList = castArray(presets);
|
|
66
|
+
config.presets = config.presets.filter((item)=>{
|
|
67
|
+
let name = getPluginItemName(item);
|
|
68
|
+
return !name || !removeList.find((removeItem)=>name.includes(removeItem));
|
|
69
|
+
});
|
|
70
|
+
}, modifyPresetOptions = (presetName, options, presets = [])=>{
|
|
71
|
+
presets.forEach((preset, index)=>{
|
|
72
|
+
Array.isArray(preset) ? 'string' == typeof preset[0] && normalizeToPosixPath(preset[0]).includes(presetName) && (preset[1] = {
|
|
178
73
|
...preset[1] || {},
|
|
179
74
|
...options
|
|
75
|
+
}) : 'string' == typeof preset && normalizeToPosixPath(preset).includes(presetName) && (presets[index] = [
|
|
76
|
+
preset,
|
|
77
|
+
options
|
|
78
|
+
]);
|
|
79
|
+
});
|
|
80
|
+
}, getBabelUtils = (config)=>{
|
|
81
|
+
let noop = ()=>{};
|
|
82
|
+
return {
|
|
83
|
+
addPlugins: (plugins)=>addPlugins(plugins, config),
|
|
84
|
+
addPresets: (presets)=>addPresets(presets, config),
|
|
85
|
+
removePlugins: (plugins)=>removePlugins(plugins, config),
|
|
86
|
+
removePresets: (presets)=>removePresets(presets, config),
|
|
87
|
+
addIncludes: noop,
|
|
88
|
+
addExcludes: noop,
|
|
89
|
+
modifyPresetEnvOptions: (options)=>modifyPresetOptions('@babel/preset-env', options, config.presets || []),
|
|
90
|
+
modifyPresetReactOptions: (options)=>modifyPresetOptions('@babel/preset-react', options, config.presets || [])
|
|
91
|
+
};
|
|
92
|
+
}, applyUserBabelConfig = (defaultOptions, userBabelConfig, extraBabelUtils)=>{
|
|
93
|
+
if (userBabelConfig) {
|
|
94
|
+
let babelUtils = {
|
|
95
|
+
...getBabelUtils(defaultOptions),
|
|
96
|
+
...extraBabelUtils
|
|
180
97
|
};
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
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 ruleId of [
|
|
107
|
+
CHAIN_ID.RULE.JS,
|
|
108
|
+
CHAIN_ID.RULE.JS_DATA_URI,
|
|
109
|
+
BABEL_JS_RULE
|
|
110
|
+
])if (chain.module.rules.has(ruleId)) {
|
|
111
|
+
let rule = chain.module.rule(ruleId);
|
|
112
|
+
rule.uses.has(CHAIN_ID.USE.BABEL) && rule.use(CHAIN_ID.USE.BABEL).tap(modifier);
|
|
113
|
+
}
|
|
114
|
+
}, 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 = {
|
|
115
|
+
allowNamespaces: !0,
|
|
116
|
+
allExtensions: !0,
|
|
117
|
+
allowDeclareFields: !0,
|
|
118
|
+
optimizeConstEnums: !0,
|
|
119
|
+
isTSX: !0
|
|
202
120
|
};
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
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
|
-
});
|
|
121
|
+
async function getCacheIdentifier(options) {
|
|
122
|
+
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 ?? '';
|
|
123
|
+
return identifier += `@babel/core@${coreVersion}babel-loader@${loaderVersion}`;
|
|
215
124
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
const plugin_dirname = external_node_path_default().dirname((0, external_node_url_namespaceObject.fileURLToPath)(/*#__PURE__*/ function() {
|
|
230
|
-
return 'undefined' == typeof document ? new (module.require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
|
|
231
|
-
}()));
|
|
232
|
-
const plugin_require = (0, external_node_module_namespaceObject.createRequire)(/*#__PURE__*/ function() {
|
|
233
|
-
return 'undefined' == typeof document ? new (module.require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
|
|
234
|
-
}());
|
|
235
|
-
const PLUGIN_BABEL_NAME = 'rsbuild:babel';
|
|
236
|
-
const SCRIPT_REGEX = /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/;
|
|
237
|
-
/**
|
|
238
|
-
* The `@babel/preset-typescript` default options.
|
|
239
|
-
*/ const DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS = {
|
|
240
|
-
allowNamespaces: true,
|
|
241
|
-
allExtensions: true,
|
|
242
|
-
allowDeclareFields: true,
|
|
243
|
-
// aligns Babel's behavior with TypeScript's default behavior.
|
|
244
|
-
// https://babeljs.io/docs/en/babel-preset-typescript#optimizeconstenums
|
|
245
|
-
optimizeConstEnums: true,
|
|
246
|
-
isTSX: true
|
|
247
|
-
};
|
|
248
|
-
function getCacheDirectory(context, cacheDirectory) {
|
|
249
|
-
if (cacheDirectory) return (0, external_node_path_namespaceObject.isAbsolute)(cacheDirectory) ? cacheDirectory : (0, external_node_path_namespaceObject.join)(context.rootPath, cacheDirectory);
|
|
250
|
-
return (0, external_node_path_namespaceObject.join)(context.cachePath);
|
|
251
|
-
}
|
|
252
|
-
async function getCacheIdentifier(options) {
|
|
253
|
-
let identifier = `${process.env.NODE_ENV}${JSON.stringify(options)}`;
|
|
254
|
-
const { version: coreVersion } = await Promise.resolve().then(__webpack_require__.t.bind(__webpack_require__, "@babel/core", 23));
|
|
255
|
-
const rawPkgJson = await external_node_fs_default().promises.readFile((0, external_node_path_namespaceObject.join)(plugin_dirname, '../compiled/babel-loader/package.json'), 'utf-8');
|
|
256
|
-
const loaderVersion = JSON.parse(rawPkgJson).version ?? '';
|
|
257
|
-
identifier += `@babel/core@${coreVersion}`;
|
|
258
|
-
identifier += `babel-loader@${loaderVersion}`;
|
|
259
|
-
return identifier;
|
|
260
|
-
}
|
|
261
|
-
const getDefaultBabelOptions = (config, context)=>{
|
|
262
|
-
const isLegacyDecorators = 'legacy' === config.source.decorators.version;
|
|
263
|
-
const options = {
|
|
264
|
-
babelrc: false,
|
|
265
|
-
configFile: false,
|
|
266
|
-
compact: 'production' === config.mode,
|
|
267
|
-
plugins: [
|
|
268
|
-
[
|
|
269
|
-
plugin_require.resolve('@babel/plugin-proposal-decorators'),
|
|
270
|
-
config.source.decorators
|
|
125
|
+
let getDefaultBabelOptions = (config, context)=>{
|
|
126
|
+
let isLegacyDecorators = 'legacy' === config.source.decorators.version, options = {
|
|
127
|
+
babelrc: !1,
|
|
128
|
+
configFile: !1,
|
|
129
|
+
compact: 'production' === config.mode,
|
|
130
|
+
plugins: [
|
|
131
|
+
[
|
|
132
|
+
plugin_require.resolve('@babel/plugin-proposal-decorators'),
|
|
133
|
+
config.source.decorators
|
|
134
|
+
],
|
|
135
|
+
...isLegacyDecorators ? [
|
|
136
|
+
plugin_require.resolve('@babel/plugin-transform-class-properties')
|
|
137
|
+
] : []
|
|
271
138
|
],
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
],
|
|
278
|
-
presets: [
|
|
279
|
-
// TODO: only apply preset-typescript for ts file (isTSX & allExtensions false)
|
|
280
|
-
[
|
|
281
|
-
plugin_require.resolve('@babel/preset-typescript'),
|
|
282
|
-
DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS
|
|
139
|
+
presets: [
|
|
140
|
+
[
|
|
141
|
+
plugin_require.resolve("@babel/preset-typescript"),
|
|
142
|
+
DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS
|
|
143
|
+
]
|
|
283
144
|
]
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
const cacheDirectory = getCacheDirectory(context, 'boolean' == typeof buildCache ? void 0 : buildCache.cacheDirectory);
|
|
291
|
-
// turn off compression to reduce overhead
|
|
292
|
-
options.cacheCompression = false;
|
|
293
|
-
options.cacheDirectory = (0, external_node_path_namespaceObject.join)(cacheDirectory, 'babel-loader');
|
|
294
|
-
}
|
|
295
|
-
return options;
|
|
296
|
-
};
|
|
297
|
-
const pluginBabel = (options = {})=>({
|
|
298
|
-
name: PLUGIN_BABEL_NAME,
|
|
299
|
-
setup (api) {
|
|
300
|
-
const getBabelOptions = async (environment)=>{
|
|
301
|
-
const { config } = environment;
|
|
302
|
-
const baseOptions = getDefaultBabelOptions(config, api.context);
|
|
303
|
-
const mergedOptions = applyUserBabelConfig(external_deepmerge_default()({}, baseOptions), options.babelLoaderOptions);
|
|
304
|
-
// calculate cacheIdentifier with the merged options
|
|
305
|
-
if (mergedOptions.cacheDirectory && !mergedOptions.cacheIdentifier) mergedOptions.cacheIdentifier = await getCacheIdentifier(mergedOptions);
|
|
306
|
-
return mergedOptions;
|
|
307
|
-
};
|
|
308
|
-
api.modifyBundlerChain({
|
|
309
|
-
order: 'pre',
|
|
310
|
-
handler: async (chain, { CHAIN_ID, environment })=>{
|
|
311
|
-
const babelOptions = await getBabelOptions(environment);
|
|
312
|
-
const babelLoader = external_node_path_default().resolve(plugin_dirname, '../compiled/babel-loader/index.js');
|
|
313
|
-
const { include, exclude } = options;
|
|
314
|
-
if (include || exclude) {
|
|
315
|
-
const rule = chain.module.rule(BABEL_JS_RULE) // run babel loader before the builtin SWC loader
|
|
316
|
-
// https://stackoverflow.com/questions/32234329/what-is-the-loader-order-for-webpack
|
|
317
|
-
.after(CHAIN_ID.RULE.JS);
|
|
318
|
-
if (include) for (const condition of castArray(include))rule.include.add(condition);
|
|
319
|
-
if (exclude) for (const condition of castArray(exclude))rule.exclude.add(condition);
|
|
320
|
-
rule.test(SCRIPT_REGEX).use(CHAIN_ID.USE.BABEL).loader(babelLoader).options(babelOptions);
|
|
321
|
-
} else {
|
|
322
|
-
// already set source.include / exclude in plugin-swc
|
|
323
|
-
const rule = chain.module.rule(CHAIN_ID.RULE.JS);
|
|
324
|
-
rule.test(SCRIPT_REGEX).use(CHAIN_ID.USE.BABEL).after(CHAIN_ID.USE.SWC).loader(babelLoader).options(babelOptions);
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
});
|
|
145
|
+
}, { buildCache = !0 } = config.performance;
|
|
146
|
+
if (buildCache && 'rspack' === context.bundlerType) {
|
|
147
|
+
let cacheDirectory = function(context, cacheDirectory) {
|
|
148
|
+
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);
|
|
149
|
+
}(context, 'boolean' == typeof buildCache ? void 0 : buildCache.cacheDirectory);
|
|
150
|
+
options.cacheCompression = !1, options.cacheDirectory = (0, external_node_path_namespaceObject.join)(cacheDirectory, 'babel-loader');
|
|
328
151
|
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
152
|
+
return options;
|
|
153
|
+
}, pluginBabel = (options = {})=>({
|
|
154
|
+
name: PLUGIN_BABEL_NAME,
|
|
155
|
+
setup (api) {
|
|
156
|
+
let getBabelOptions = async (environment)=>{
|
|
157
|
+
let { config } = environment, baseOptions = getDefaultBabelOptions(config, api.context), mergedOptions = applyUserBabelConfig(external_deepmerge_default()({}, baseOptions), options.babelLoaderOptions);
|
|
158
|
+
return mergedOptions.cacheDirectory && !mergedOptions.cacheIdentifier && (mergedOptions.cacheIdentifier = await getCacheIdentifier(mergedOptions)), mergedOptions;
|
|
159
|
+
};
|
|
160
|
+
api.modifyBundlerChain({
|
|
161
|
+
order: 'pre',
|
|
162
|
+
handler: async (chain, { CHAIN_ID, environment })=>{
|
|
163
|
+
let babelOptions = await getBabelOptions(environment), babelLoader = external_node_path_default().resolve(plugin_dirname, '../compiled/babel-loader/index.js'), { include, exclude } = options;
|
|
164
|
+
if (include || exclude) {
|
|
165
|
+
let rule = chain.module.rule(BABEL_JS_RULE).after(CHAIN_ID.RULE.JS);
|
|
166
|
+
if (include) for (let condition of castArray(include))rule.include.add(condition);
|
|
167
|
+
if (exclude) for (let condition of castArray(exclude))rule.exclude.add(condition);
|
|
168
|
+
rule.test(SCRIPT_REGEX).use(CHAIN_ID.USE.BABEL).loader(babelLoader).options(babelOptions);
|
|
169
|
+
} 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);
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
})(), 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 === [
|
|
175
|
+
"PLUGIN_BABEL_NAME",
|
|
176
|
+
"getBabelUtils",
|
|
177
|
+
"getDefaultBabelOptions",
|
|
178
|
+
"modifyBabelLoaderOptions",
|
|
179
|
+
"pluginBabel"
|
|
180
|
+
].indexOf(__webpack_i__) && (exports[__webpack_i__] = __webpack_exports__[__webpack_i__]);
|
|
181
|
+
Object.defineProperty(exports, '__esModule', {
|
|
182
|
+
value: !0
|
|
334
183
|
});
|