@rsbuild/plugin-babel 0.7.10 → 1.0.0-alpha.1
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 +13 -13
- package/dist/helper.d.ts +11 -0
- package/dist/index.cjs +14 -8
- package/dist/index.d.ts +3 -112
- package/dist/index.js +16 -17
- package/dist/plugin.d.ts +15 -0
- package/dist/types.d.ts +97 -0
- package/package.json +7 -6
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/******/ (() => { // webpackBootstrap
|
|
2
2
|
/******/ var __webpack_modules__ = ({
|
|
3
3
|
|
|
4
|
-
/***/
|
|
4
|
+
/***/ 95:
|
|
5
5
|
/***/ ((module) => {
|
|
6
6
|
|
|
7
7
|
const STRIP_FILENAME_RE = /^[^:]+: /;
|
|
@@ -36,7 +36,7 @@ module.exports = LoaderError;
|
|
|
36
36
|
|
|
37
37
|
/***/ }),
|
|
38
38
|
|
|
39
|
-
/***/
|
|
39
|
+
/***/ 208:
|
|
40
40
|
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
|
|
41
41
|
|
|
42
42
|
/**
|
|
@@ -61,7 +61,7 @@ const {
|
|
|
61
61
|
mkdir
|
|
62
62
|
} = __nccwpck_require__(292);
|
|
63
63
|
const findCacheDirP = __nccwpck_require__.e(/* import() */ 672).then(__nccwpck_require__.bind(__nccwpck_require__, 672));
|
|
64
|
-
const transform = __nccwpck_require__(
|
|
64
|
+
const transform = __nccwpck_require__(421);
|
|
65
65
|
// Lazily instantiated when needed
|
|
66
66
|
let defaultCacheDirectory = null;
|
|
67
67
|
let hashType = "sha256";
|
|
@@ -220,7 +220,7 @@ module.exports = async function (params) {
|
|
|
220
220
|
|
|
221
221
|
/***/ }),
|
|
222
222
|
|
|
223
|
-
/***/
|
|
223
|
+
/***/ 362:
|
|
224
224
|
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
|
|
225
225
|
|
|
226
226
|
let babel;
|
|
@@ -241,10 +241,10 @@ if (/^6\./.test(babel.version)) {
|
|
|
241
241
|
const {
|
|
242
242
|
version
|
|
243
243
|
} = __nccwpck_require__(684);
|
|
244
|
-
const cache = __nccwpck_require__(
|
|
245
|
-
const transform = __nccwpck_require__(
|
|
246
|
-
const injectCaller = __nccwpck_require__(
|
|
247
|
-
const schema = __nccwpck_require__(
|
|
244
|
+
const cache = __nccwpck_require__(208);
|
|
245
|
+
const transform = __nccwpck_require__(421);
|
|
246
|
+
const injectCaller = __nccwpck_require__(374);
|
|
247
|
+
const schema = __nccwpck_require__(416);
|
|
248
248
|
const {
|
|
249
249
|
isAbsolute
|
|
250
250
|
} = __nccwpck_require__(17);
|
|
@@ -404,7 +404,7 @@ async function loader(source, inputSourceMap, overrides) {
|
|
|
404
404
|
|
|
405
405
|
/***/ }),
|
|
406
406
|
|
|
407
|
-
/***/
|
|
407
|
+
/***/ 374:
|
|
408
408
|
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
|
|
409
409
|
|
|
410
410
|
const babel = __nccwpck_require__(718);
|
|
@@ -451,14 +451,14 @@ function supportsCallerOption() {
|
|
|
451
451
|
|
|
452
452
|
/***/ }),
|
|
453
453
|
|
|
454
|
-
/***/
|
|
454
|
+
/***/ 421:
|
|
455
455
|
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
|
|
456
456
|
|
|
457
457
|
const babel = __nccwpck_require__(718);
|
|
458
458
|
const {
|
|
459
459
|
promisify
|
|
460
460
|
} = __nccwpck_require__(837);
|
|
461
|
-
const LoaderError = __nccwpck_require__(
|
|
461
|
+
const LoaderError = __nccwpck_require__(95);
|
|
462
462
|
const transform = promisify(babel.transform);
|
|
463
463
|
module.exports = async function (source, options) {
|
|
464
464
|
let result;
|
|
@@ -603,7 +603,7 @@ module.exports = require("zlib");
|
|
|
603
603
|
|
|
604
604
|
/***/ }),
|
|
605
605
|
|
|
606
|
-
/***/
|
|
606
|
+
/***/ 416:
|
|
607
607
|
/***/ ((module) => {
|
|
608
608
|
|
|
609
609
|
"use strict";
|
|
@@ -748,7 +748,7 @@ module.exports = JSON.parse('{"type":"object","properties":{"cacheDirectory":{"o
|
|
|
748
748
|
/******/ // startup
|
|
749
749
|
/******/ // Load entry module and return exports
|
|
750
750
|
/******/ // This entry module is referenced by other modules so it can't be inlined
|
|
751
|
-
/******/ var __webpack_exports__ = __nccwpck_require__(
|
|
751
|
+
/******/ var __webpack_exports__ = __nccwpck_require__(362);
|
|
752
752
|
/******/ module.exports = __webpack_exports__;
|
|
753
753
|
/******/
|
|
754
754
|
/******/ })()
|
package/dist/helper.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ChainIdentifier, NormalizedConfig, RspackChain } from '@rsbuild/core';
|
|
2
|
+
import type { BabelConfigUtils, BabelLoaderOptions, BabelTransformOptions, PluginBabelOptions } from './types';
|
|
3
|
+
export declare const BABEL_JS_RULE = "babel-js";
|
|
4
|
+
export declare const getBabelUtils: (config: BabelTransformOptions) => BabelConfigUtils;
|
|
5
|
+
export declare const applyUserBabelConfig: (defaultOptions: BabelLoaderOptions, userBabelConfig?: PluginBabelOptions["babelLoaderOptions"], extraBabelUtils?: Partial<BabelConfigUtils>) => BabelLoaderOptions;
|
|
6
|
+
export declare const getUseBuiltIns: (config: NormalizedConfig) => false | "usage" | "entry";
|
|
7
|
+
export declare const modifyBabelLoaderOptions: ({ chain, CHAIN_ID, modifier, }: {
|
|
8
|
+
chain: RspackChain;
|
|
9
|
+
CHAIN_ID: ChainIdentifier;
|
|
10
|
+
modifier: (config: BabelTransformOptions) => BabelTransformOptions;
|
|
11
|
+
}) => void;
|
package/dist/index.cjs
CHANGED
|
@@ -40,12 +40,14 @@ __export(src_exports, {
|
|
|
40
40
|
module.exports = __toCommonJS(src_exports);
|
|
41
41
|
|
|
42
42
|
// src/plugin.ts
|
|
43
|
+
var import_node_fs = __toESM(require("fs"));
|
|
43
44
|
var import_node_path2 = __toESM(require("path"));
|
|
44
45
|
var import_shared2 = require("@rsbuild/shared");
|
|
45
46
|
|
|
46
47
|
// src/helper.ts
|
|
47
48
|
var import_node_path = require("path");
|
|
48
49
|
var import_shared = require("@rsbuild/shared");
|
|
50
|
+
var import_reduce_configs = require("reduce-configs");
|
|
49
51
|
var import_upath = __toESM(require("upath"));
|
|
50
52
|
var BABEL_JS_RULE = "babel-js";
|
|
51
53
|
var normalizeToPosixPath = (p) => import_upath.default.normalizeSafe((0, import_node_path.normalize)(p || "")).replace(/^([a-zA-Z]+):/, (_, m) => `/${m.toLowerCase()}`);
|
|
@@ -142,7 +144,7 @@ var applyUserBabelConfig = (defaultOptions, userBabelConfig, extraBabelUtils) =>
|
|
|
142
144
|
...getBabelUtils(defaultOptions),
|
|
143
145
|
...extraBabelUtils
|
|
144
146
|
};
|
|
145
|
-
return (0,
|
|
147
|
+
return (0, import_reduce_configs.reduceConfigsWithContext)({
|
|
146
148
|
initial: defaultOptions,
|
|
147
149
|
config: userBabelConfig,
|
|
148
150
|
ctx: babelUtils
|
|
@@ -191,9 +193,13 @@ function getCacheDirectory(context, cacheDirectory) {
|
|
|
191
193
|
return (0, import_node_path2.join)(context.cachePath);
|
|
192
194
|
}
|
|
193
195
|
async function getCacheIdentifier(options) {
|
|
194
|
-
let identifier = `${
|
|
196
|
+
let identifier = `${process.env.NODE_ENV}${JSON.stringify(options)}`;
|
|
195
197
|
const { version: coreVersion } = await import("@babel/core");
|
|
196
|
-
const
|
|
198
|
+
const rawPkgJson = await import_node_fs.default.promises.readFile(
|
|
199
|
+
(0, import_node_path2.join)(__dirname, "../compiled/babel-loader/package.json"),
|
|
200
|
+
"utf-8"
|
|
201
|
+
);
|
|
202
|
+
const loaderVersion = JSON.parse(rawPkgJson).version ?? "";
|
|
197
203
|
identifier += `@babel/core@${coreVersion}`;
|
|
198
204
|
identifier += `babel-loader@${loaderVersion}`;
|
|
199
205
|
return identifier;
|
|
@@ -203,7 +209,7 @@ var getDefaultBabelOptions = (config, context) => {
|
|
|
203
209
|
const options = {
|
|
204
210
|
babelrc: false,
|
|
205
211
|
configFile: false,
|
|
206
|
-
compact:
|
|
212
|
+
compact: process.env.NODE_ENV === "production",
|
|
207
213
|
plugins: [
|
|
208
214
|
[
|
|
209
215
|
require.resolve("@babel/plugin-proposal-decorators"),
|
|
@@ -235,8 +241,8 @@ var getDefaultBabelOptions = (config, context) => {
|
|
|
235
241
|
var pluginBabel = (options = {}) => ({
|
|
236
242
|
name: PLUGIN_BABEL_NAME,
|
|
237
243
|
setup(api) {
|
|
238
|
-
const getBabelOptions = async () => {
|
|
239
|
-
const config =
|
|
244
|
+
const getBabelOptions = async (environment) => {
|
|
245
|
+
const { config } = environment;
|
|
240
246
|
const baseOptions = getDefaultBabelOptions(config, api.context);
|
|
241
247
|
const mergedOptions = applyUserBabelConfig(
|
|
242
248
|
(0, import_shared2.cloneDeep)(baseOptions),
|
|
@@ -249,8 +255,8 @@ var pluginBabel = (options = {}) => ({
|
|
|
249
255
|
};
|
|
250
256
|
api.modifyBundlerChain({
|
|
251
257
|
order: "pre",
|
|
252
|
-
handler: async (chain, { CHAIN_ID }) => {
|
|
253
|
-
const babelOptions = await getBabelOptions();
|
|
258
|
+
handler: async (chain, { CHAIN_ID, environment }) => {
|
|
259
|
+
const babelOptions = await getBabelOptions(environment);
|
|
254
260
|
const babelLoader = import_node_path2.default.resolve(
|
|
255
261
|
__dirname,
|
|
256
262
|
"../compiled/babel-loader/index.js"
|
package/dist/index.d.ts
CHANGED
|
@@ -1,112 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export {
|
|
4
|
-
|
|
5
|
-
type PresetEnvTargets = string | string[] | Record<string, string>;
|
|
6
|
-
type PresetEnvBuiltIns = 'usage' | 'entry' | false;
|
|
7
|
-
type PresetEnvOptions = {
|
|
8
|
-
targets?: PresetEnvTargets;
|
|
9
|
-
bugfixes?: boolean;
|
|
10
|
-
spec?: boolean;
|
|
11
|
-
loose?: boolean;
|
|
12
|
-
modules?: 'amd' | 'umd' | 'systemjs' | 'commonjs' | 'cjs' | 'auto' | false;
|
|
13
|
-
debug?: boolean;
|
|
14
|
-
include?: string[];
|
|
15
|
-
exclude?: string[];
|
|
16
|
-
useBuiltIns?: PresetEnvBuiltIns;
|
|
17
|
-
corejs?: string | {
|
|
18
|
-
version: string;
|
|
19
|
-
proposals: boolean;
|
|
20
|
-
};
|
|
21
|
-
forceAllTransforms?: boolean;
|
|
22
|
-
configPath?: string;
|
|
23
|
-
ignoreBrowserslistConfig?: boolean;
|
|
24
|
-
browserslistEnv?: string;
|
|
25
|
-
shippedProposals?: boolean;
|
|
26
|
-
};
|
|
27
|
-
interface SharedBabelPresetReactOptions {
|
|
28
|
-
development?: boolean;
|
|
29
|
-
throwIfNamespace?: boolean;
|
|
30
|
-
}
|
|
31
|
-
interface AutomaticRuntimePresetReactOptions extends SharedBabelPresetReactOptions {
|
|
32
|
-
runtime?: 'automatic';
|
|
33
|
-
importSource?: string;
|
|
34
|
-
}
|
|
35
|
-
interface ClassicRuntimePresetReactOptions extends SharedBabelPresetReactOptions {
|
|
36
|
-
runtime?: 'classic';
|
|
37
|
-
pragma?: string;
|
|
38
|
-
pragmaFrag?: string;
|
|
39
|
-
useBuiltIns?: boolean;
|
|
40
|
-
useSpread?: boolean;
|
|
41
|
-
}
|
|
42
|
-
type PresetReactOptions = AutomaticRuntimePresetReactOptions | ClassicRuntimePresetReactOptions;
|
|
43
|
-
type RuleCondition = string | RegExp | (string | RegExp)[];
|
|
44
|
-
type BabelConfigUtils = {
|
|
45
|
-
addPlugins: (plugins: PluginItem[]) => void;
|
|
46
|
-
addPresets: (presets: PluginItem[]) => void;
|
|
47
|
-
removePlugins: (plugins: string | string[]) => void;
|
|
48
|
-
removePresets: (presets: string | string[]) => void;
|
|
49
|
-
modifyPresetEnvOptions: (options: PresetEnvOptions) => void;
|
|
50
|
-
modifyPresetReactOptions: (options: PresetReactOptions) => void;
|
|
51
|
-
/**
|
|
52
|
-
* use `source.include` instead
|
|
53
|
-
* @deprecated
|
|
54
|
-
*/
|
|
55
|
-
addIncludes: (includes: RuleCondition) => void;
|
|
56
|
-
/**
|
|
57
|
-
* use `source.exclude` instead
|
|
58
|
-
* @deprecated
|
|
59
|
-
*/
|
|
60
|
-
addExcludes: (excludes: RuleCondition) => void;
|
|
61
|
-
};
|
|
62
|
-
type BabelLoaderOptions = TransformOptions & {
|
|
63
|
-
/**
|
|
64
|
-
* When set, the given directory will be used to cache the results of the loader.
|
|
65
|
-
*/
|
|
66
|
-
cacheDirectory?: string | boolean;
|
|
67
|
-
/**
|
|
68
|
-
* Can be set to a custom value to force cache busting if the identifier changes.
|
|
69
|
-
*/
|
|
70
|
-
cacheIdentifier?: string;
|
|
71
|
-
/**
|
|
72
|
-
* When set, each Babel transform output will be compressed with Gzip.
|
|
73
|
-
*/
|
|
74
|
-
cacheCompression?: boolean;
|
|
75
|
-
/**
|
|
76
|
-
* The path of a module that exports a custom callback.
|
|
77
|
-
*/
|
|
78
|
-
customize?: string | null;
|
|
79
|
-
/**
|
|
80
|
-
* Takes an array of context function names. E.g.
|
|
81
|
-
*/
|
|
82
|
-
metadataSubscribers?: string[];
|
|
83
|
-
};
|
|
84
|
-
type PluginBabelOptions = {
|
|
85
|
-
/**
|
|
86
|
-
* Used to specify the files that need to be compiled by Babel.
|
|
87
|
-
*/
|
|
88
|
-
include?: RuleCondition;
|
|
89
|
-
/**
|
|
90
|
-
* Used to specify the files that do not need to be compiled by Babel.
|
|
91
|
-
*/
|
|
92
|
-
exclude?: RuleCondition;
|
|
93
|
-
/**
|
|
94
|
-
* Options passed to `babel-loader`.
|
|
95
|
-
* @see https://github.com/babel/babel-loader
|
|
96
|
-
*/
|
|
97
|
-
babelLoaderOptions?: ConfigChainWithContext<BabelLoaderOptions, BabelConfigUtils>;
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
declare const PLUGIN_BABEL_NAME = "rsbuild:babel";
|
|
101
|
-
declare const getDefaultBabelOptions: (config: NormalizedConfig, context: RsbuildContext) => BabelLoaderOptions;
|
|
102
|
-
declare const pluginBabel: (options?: PluginBabelOptions) => RsbuildPlugin;
|
|
103
|
-
|
|
104
|
-
declare const getBabelUtils: (config: TransformOptions) => BabelConfigUtils;
|
|
105
|
-
declare const getUseBuiltIns: (config: NormalizedConfig) => false | "usage" | "entry";
|
|
106
|
-
declare const modifyBabelLoaderOptions: ({ chain, CHAIN_ID, modifier, }: {
|
|
107
|
-
chain: RspackChain;
|
|
108
|
-
CHAIN_ID: ChainIdentifier;
|
|
109
|
-
modifier: (config: TransformOptions) => TransformOptions;
|
|
110
|
-
}) => void;
|
|
111
|
-
|
|
112
|
-
export { type BabelConfigUtils, PLUGIN_BABEL_NAME, type PluginBabelOptions, type PresetEnvBuiltIns, type PresetEnvOptions, type PresetEnvTargets, getBabelUtils, getDefaultBabelOptions, getUseBuiltIns, modifyBabelLoaderOptions, pluginBabel };
|
|
1
|
+
export { pluginBabel, getDefaultBabelOptions, PLUGIN_BABEL_NAME, } from './plugin';
|
|
2
|
+
export { getBabelUtils, getUseBuiltIns, modifyBabelLoaderOptions, } from './helper';
|
|
3
|
+
export type { PresetEnvOptions, PresetEnvTargets, PresetEnvBuiltIns, BabelConfigUtils, BabelTransformOptions, PluginBabelOptions, } from './types';
|
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
9
9
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
10
10
|
});
|
|
11
11
|
|
|
12
|
-
// ../../node_modules/.pnpm/@modern-js+module-tools@2.
|
|
12
|
+
// ../../node_modules/.pnpm/@modern-js+module-tools@2.54.5_eslint@9.6.0_typescript@5.5.2/node_modules/@modern-js/module-tools/shims/esm.js
|
|
13
13
|
import { fileURLToPath } from "url";
|
|
14
14
|
import path from "path";
|
|
15
15
|
var getFilename = () => fileURLToPath(import.meta.url);
|
|
@@ -17,19 +17,14 @@ var getDirname = () => path.dirname(getFilename());
|
|
|
17
17
|
var __dirname = /* @__PURE__ */ getDirname();
|
|
18
18
|
|
|
19
19
|
// src/plugin.ts
|
|
20
|
+
import fs from "fs";
|
|
20
21
|
import path2, { isAbsolute as isAbsolute2, join } from "path";
|
|
21
|
-
import {
|
|
22
|
-
SCRIPT_REGEX,
|
|
23
|
-
castArray as castArray2,
|
|
24
|
-
cloneDeep,
|
|
25
|
-
fse,
|
|
26
|
-
getNodeEnv,
|
|
27
|
-
isProd
|
|
28
|
-
} from "@rsbuild/shared";
|
|
22
|
+
import { SCRIPT_REGEX, castArray as castArray2, cloneDeep } from "@rsbuild/shared";
|
|
29
23
|
|
|
30
24
|
// src/helper.ts
|
|
31
25
|
import { isAbsolute, normalize, sep } from "path";
|
|
32
|
-
import { castArray
|
|
26
|
+
import { castArray } from "@rsbuild/shared";
|
|
27
|
+
import { reduceConfigsWithContext } from "reduce-configs";
|
|
33
28
|
import upath from "upath";
|
|
34
29
|
var BABEL_JS_RULE = "babel-js";
|
|
35
30
|
var normalizeToPosixPath = (p) => upath.normalizeSafe(normalize(p || "")).replace(/^([a-zA-Z]+):/, (_, m) => `/${m.toLowerCase()}`);
|
|
@@ -175,9 +170,13 @@ function getCacheDirectory(context, cacheDirectory) {
|
|
|
175
170
|
return join(context.cachePath);
|
|
176
171
|
}
|
|
177
172
|
async function getCacheIdentifier(options) {
|
|
178
|
-
let identifier = `${
|
|
173
|
+
let identifier = `${process.env.NODE_ENV}${JSON.stringify(options)}`;
|
|
179
174
|
const { version: coreVersion } = await import("@babel/core");
|
|
180
|
-
const
|
|
175
|
+
const rawPkgJson = await fs.promises.readFile(
|
|
176
|
+
join(__dirname, "../compiled/babel-loader/package.json"),
|
|
177
|
+
"utf-8"
|
|
178
|
+
);
|
|
179
|
+
const loaderVersion = JSON.parse(rawPkgJson).version ?? "";
|
|
181
180
|
identifier += `@babel/core@${coreVersion}`;
|
|
182
181
|
identifier += `babel-loader@${loaderVersion}`;
|
|
183
182
|
return identifier;
|
|
@@ -187,7 +186,7 @@ var getDefaultBabelOptions = (config, context) => {
|
|
|
187
186
|
const options = {
|
|
188
187
|
babelrc: false,
|
|
189
188
|
configFile: false,
|
|
190
|
-
compact:
|
|
189
|
+
compact: process.env.NODE_ENV === "production",
|
|
191
190
|
plugins: [
|
|
192
191
|
[
|
|
193
192
|
__require.resolve("@babel/plugin-proposal-decorators"),
|
|
@@ -219,8 +218,8 @@ var getDefaultBabelOptions = (config, context) => {
|
|
|
219
218
|
var pluginBabel = (options = {}) => ({
|
|
220
219
|
name: PLUGIN_BABEL_NAME,
|
|
221
220
|
setup(api) {
|
|
222
|
-
const getBabelOptions = async () => {
|
|
223
|
-
const config =
|
|
221
|
+
const getBabelOptions = async (environment) => {
|
|
222
|
+
const { config } = environment;
|
|
224
223
|
const baseOptions = getDefaultBabelOptions(config, api.context);
|
|
225
224
|
const mergedOptions = applyUserBabelConfig(
|
|
226
225
|
cloneDeep(baseOptions),
|
|
@@ -233,8 +232,8 @@ var pluginBabel = (options = {}) => ({
|
|
|
233
232
|
};
|
|
234
233
|
api.modifyBundlerChain({
|
|
235
234
|
order: "pre",
|
|
236
|
-
handler: async (chain, { CHAIN_ID }) => {
|
|
237
|
-
const babelOptions = await getBabelOptions();
|
|
235
|
+
handler: async (chain, { CHAIN_ID, environment }) => {
|
|
236
|
+
const babelOptions = await getBabelOptions(environment);
|
|
238
237
|
const babelLoader = path2.resolve(
|
|
239
238
|
__dirname,
|
|
240
239
|
"../compiled/babel-loader/index.js"
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { NormalizedEnvironmentConfig, RsbuildContext, RsbuildPlugin } from '@rsbuild/core';
|
|
2
|
+
import type { BabelLoaderOptions, PluginBabelOptions } from './types';
|
|
3
|
+
export declare const PLUGIN_BABEL_NAME = "rsbuild:babel";
|
|
4
|
+
/**
|
|
5
|
+
* The `@babel/preset-typescript` default options.
|
|
6
|
+
*/
|
|
7
|
+
export declare const DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS: {
|
|
8
|
+
allowNamespaces: boolean;
|
|
9
|
+
allExtensions: boolean;
|
|
10
|
+
allowDeclareFields: boolean;
|
|
11
|
+
optimizeConstEnums: boolean;
|
|
12
|
+
isTSX: boolean;
|
|
13
|
+
};
|
|
14
|
+
export declare const getDefaultBabelOptions: (config: NormalizedEnvironmentConfig, context: RsbuildContext) => BabelLoaderOptions;
|
|
15
|
+
export declare const pluginBabel: (options?: PluginBabelOptions) => RsbuildPlugin;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { PluginItem as BabelPlugin, TransformOptions as BabelTransformOptions } from '@babel/core';
|
|
2
|
+
import type { ConfigChainWithContext } from '@rsbuild/core';
|
|
3
|
+
export type { BabelPlugin, BabelTransformOptions };
|
|
4
|
+
export type PresetEnvTargets = string | string[] | Record<string, string>;
|
|
5
|
+
export type PresetEnvBuiltIns = 'usage' | 'entry' | false;
|
|
6
|
+
export type PresetEnvOptions = {
|
|
7
|
+
targets?: PresetEnvTargets;
|
|
8
|
+
bugfixes?: boolean;
|
|
9
|
+
spec?: boolean;
|
|
10
|
+
loose?: boolean;
|
|
11
|
+
modules?: 'amd' | 'umd' | 'systemjs' | 'commonjs' | 'cjs' | 'auto' | false;
|
|
12
|
+
debug?: boolean;
|
|
13
|
+
include?: string[];
|
|
14
|
+
exclude?: string[];
|
|
15
|
+
useBuiltIns?: PresetEnvBuiltIns;
|
|
16
|
+
corejs?: string | {
|
|
17
|
+
version: string;
|
|
18
|
+
proposals: boolean;
|
|
19
|
+
};
|
|
20
|
+
forceAllTransforms?: boolean;
|
|
21
|
+
configPath?: string;
|
|
22
|
+
ignoreBrowserslistConfig?: boolean;
|
|
23
|
+
browserslistEnv?: string;
|
|
24
|
+
shippedProposals?: boolean;
|
|
25
|
+
};
|
|
26
|
+
export interface SharedBabelPresetReactOptions {
|
|
27
|
+
development?: boolean;
|
|
28
|
+
throwIfNamespace?: boolean;
|
|
29
|
+
}
|
|
30
|
+
export interface AutomaticRuntimePresetReactOptions extends SharedBabelPresetReactOptions {
|
|
31
|
+
runtime?: 'automatic';
|
|
32
|
+
importSource?: string;
|
|
33
|
+
}
|
|
34
|
+
export interface ClassicRuntimePresetReactOptions extends SharedBabelPresetReactOptions {
|
|
35
|
+
runtime?: 'classic';
|
|
36
|
+
pragma?: string;
|
|
37
|
+
pragmaFrag?: string;
|
|
38
|
+
useBuiltIns?: boolean;
|
|
39
|
+
useSpread?: boolean;
|
|
40
|
+
}
|
|
41
|
+
export type PresetReactOptions = AutomaticRuntimePresetReactOptions | ClassicRuntimePresetReactOptions;
|
|
42
|
+
export type RuleCondition = string | RegExp | (string | RegExp)[];
|
|
43
|
+
export type BabelConfigUtils = {
|
|
44
|
+
addPlugins: (plugins: BabelPlugin[]) => void;
|
|
45
|
+
addPresets: (presets: BabelPlugin[]) => void;
|
|
46
|
+
removePlugins: (plugins: string | string[]) => void;
|
|
47
|
+
removePresets: (presets: string | string[]) => void;
|
|
48
|
+
modifyPresetEnvOptions: (options: PresetEnvOptions) => void;
|
|
49
|
+
modifyPresetReactOptions: (options: PresetReactOptions) => void;
|
|
50
|
+
/**
|
|
51
|
+
* use `source.include` instead
|
|
52
|
+
* @deprecated
|
|
53
|
+
*/
|
|
54
|
+
addIncludes: (includes: RuleCondition) => void;
|
|
55
|
+
/**
|
|
56
|
+
* use `source.exclude` instead
|
|
57
|
+
* @deprecated
|
|
58
|
+
*/
|
|
59
|
+
addExcludes: (excludes: RuleCondition) => void;
|
|
60
|
+
};
|
|
61
|
+
export type BabelLoaderOptions = BabelTransformOptions & {
|
|
62
|
+
/**
|
|
63
|
+
* When set, the given directory will be used to cache the results of the loader.
|
|
64
|
+
*/
|
|
65
|
+
cacheDirectory?: string | boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Can be set to a custom value to force cache busting if the identifier changes.
|
|
68
|
+
*/
|
|
69
|
+
cacheIdentifier?: string;
|
|
70
|
+
/**
|
|
71
|
+
* When set, each Babel transform output will be compressed with Gzip.
|
|
72
|
+
*/
|
|
73
|
+
cacheCompression?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* The path of a module that exports a custom callback.
|
|
76
|
+
*/
|
|
77
|
+
customize?: string | null;
|
|
78
|
+
/**
|
|
79
|
+
* Takes an array of context function names. E.g.
|
|
80
|
+
*/
|
|
81
|
+
metadataSubscribers?: string[];
|
|
82
|
+
};
|
|
83
|
+
export type PluginBabelOptions = {
|
|
84
|
+
/**
|
|
85
|
+
* Used to specify the files that need to be compiled by Babel.
|
|
86
|
+
*/
|
|
87
|
+
include?: RuleCondition;
|
|
88
|
+
/**
|
|
89
|
+
* Used to specify the files that do not need to be compiled by Babel.
|
|
90
|
+
*/
|
|
91
|
+
exclude?: RuleCondition;
|
|
92
|
+
/**
|
|
93
|
+
* Options passed to `babel-loader`.
|
|
94
|
+
* @see https://github.com/babel/babel-loader
|
|
95
|
+
*/
|
|
96
|
+
babelLoaderOptions?: ConfigChainWithContext<BabelLoaderOptions, BabelConfigUtils>;
|
|
97
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/plugin-babel",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-alpha.1",
|
|
4
4
|
"description": "Babel plugin for Rsbuild",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -28,19 +28,20 @@
|
|
|
28
28
|
"@babel/plugin-transform-class-properties": "^7.24.7",
|
|
29
29
|
"@babel/preset-typescript": "^7.24.7",
|
|
30
30
|
"@types/babel__core": "^7.20.5",
|
|
31
|
+
"reduce-configs": "^1.0.0",
|
|
31
32
|
"upath": "2.0.1",
|
|
32
|
-
"@rsbuild/shared": "0.
|
|
33
|
+
"@rsbuild/shared": "1.0.0-alpha.1"
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|
|
35
36
|
"@types/node": "18.x",
|
|
36
37
|
"babel-loader": "9.1.3",
|
|
37
38
|
"prebundle": "1.1.0",
|
|
38
|
-
"typescript": "^5.
|
|
39
|
-
"@rsbuild/core": "0.
|
|
40
|
-
"@scripts/test-helper": "0.
|
|
39
|
+
"typescript": "^5.5.2",
|
|
40
|
+
"@rsbuild/core": "1.0.0-alpha.0",
|
|
41
|
+
"@scripts/test-helper": "1.0.0-alpha.1"
|
|
41
42
|
},
|
|
42
43
|
"peerDependencies": {
|
|
43
|
-
"@rsbuild/core": "^0.
|
|
44
|
+
"@rsbuild/core": "^1.0.0-alpha.1"
|
|
44
45
|
},
|
|
45
46
|
"publishConfig": {
|
|
46
47
|
"access": "public",
|