@rsbuild/webpack 0.1.1 → 0.1.3
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/dist/core/build.js +3 -3
- package/dist/core/createCompiler.js +3 -1
- package/dist/core/initConfigs.js +3 -16
- package/dist/core/initHooks.d.ts +4 -3
- package/dist/core/initHooks.js +2 -0
- package/dist/core/initPlugins.js +2 -0
- package/dist/core/inspectConfig.d.ts +11 -1
- package/dist/core/inspectConfig.js +6 -2
- package/dist/core/webpackConfig.js +11 -7
- package/dist/plugins/babel.d.ts +1 -2
- package/dist/plugins/babel.js +5 -17
- package/dist/plugins/basic.js +1 -1
- package/dist/plugins/copy.js +5 -6
- package/dist/plugins/hmr.js +3 -3
- package/dist/plugins/output.js +2 -3
- package/dist/plugins/progress.js +2 -3
- package/dist/plugins/react.js +11 -5
- package/dist/plugins/resolve.js +1 -1
- package/dist/provider.d.ts +1 -2
- package/dist/provider.js +25 -5
- package/dist/shared/plugin.js +36 -40
- package/dist/types/config/tools.d.ts +2 -11
- package/dist/types/plugin.d.ts +1 -2
- package/dist/types/thirdParty/index.d.ts +0 -2
- package/dist/webpackPlugins/ProgressPlugin/helpers/bus.js +2 -6
- package/package.json +8 -9
- package/dist/plugins/tsLoader.d.ts +0 -2
- package/dist/plugins/tsLoader.js +0 -105
package/dist/core/build.js
CHANGED
|
@@ -28,7 +28,7 @@ var import_shared = require("@rsbuild/shared");
|
|
|
28
28
|
const webpackBuild = async (compiler) => {
|
|
29
29
|
return new Promise((resolve, reject) => {
|
|
30
30
|
compiler.run((err, stats) => {
|
|
31
|
-
if (err ||
|
|
31
|
+
if (err || stats?.hasErrors()) {
|
|
32
32
|
const buildError = err || new Error("Webpack build failed!");
|
|
33
33
|
reject(buildError);
|
|
34
34
|
} else {
|
|
@@ -67,9 +67,9 @@ const build = async (initOptions, { mode = "production", watch, compiler: custom
|
|
|
67
67
|
}
|
|
68
68
|
});
|
|
69
69
|
} else {
|
|
70
|
-
const executeResult = await
|
|
70
|
+
const executeResult = await executer?.(compiler);
|
|
71
71
|
await context.hooks.onAfterBuildHook.call({
|
|
72
|
-
stats: executeResult
|
|
72
|
+
stats: executeResult?.stats
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
75
|
};
|
|
@@ -61,7 +61,9 @@ async function createCompiler({
|
|
|
61
61
|
}
|
|
62
62
|
isFirstCompile = false;
|
|
63
63
|
});
|
|
64
|
-
await context.hooks.onAfterCreateCompilerHook.call({
|
|
64
|
+
await context.hooks.onAfterCreateCompilerHook.call({
|
|
65
|
+
compiler
|
|
66
|
+
});
|
|
65
67
|
(0, import_shared.debug)("create compiler done");
|
|
66
68
|
return compiler;
|
|
67
69
|
}
|
package/dist/core/initConfigs.js
CHANGED
|
@@ -25,29 +25,16 @@ var import_shared = require("@rsbuild/shared");
|
|
|
25
25
|
var import_rspack_provider = require("@rsbuild/core/rspack-provider");
|
|
26
26
|
var import_inspectConfig = require("./inspectConfig");
|
|
27
27
|
var import_webpackConfig = require("./webpackConfig");
|
|
28
|
-
var import_normalize = require("../config/normalize");
|
|
29
|
-
async function modifyRsbuildConfig(context) {
|
|
30
|
-
(0, import_shared.debug)("modify Rsbuild config");
|
|
31
|
-
const [modified] = await context.hooks.modifyRsbuildConfigHook.call(
|
|
32
|
-
context.config,
|
|
33
|
-
{ mergeRsbuildConfig: import_shared.mergeRsbuildConfig }
|
|
34
|
-
);
|
|
35
|
-
context.config = modified;
|
|
36
|
-
(0, import_shared.debug)("modify Rsbuild config done");
|
|
37
|
-
}
|
|
38
28
|
async function initConfigs({
|
|
39
29
|
context,
|
|
40
30
|
pluginStore,
|
|
41
31
|
rsbuildOptions
|
|
42
32
|
}) {
|
|
43
|
-
await (0,
|
|
44
|
-
|
|
33
|
+
await (0, import_rspack_provider.initRsbuildConfig)({
|
|
34
|
+
// @ts-expect-error context type mismatch
|
|
35
|
+
context,
|
|
45
36
|
pluginStore
|
|
46
37
|
});
|
|
47
|
-
await modifyRsbuildConfig(context);
|
|
48
|
-
const normalizedConfig = (0, import_normalize.normalizeConfig)(context.config);
|
|
49
|
-
context.normalizedConfig = normalizedConfig;
|
|
50
|
-
(0, import_rspack_provider.updateContextByNormalizedConfig)(context, context.normalizedConfig);
|
|
51
38
|
const targets = (0, import_shared.castArray)(rsbuildOptions.target);
|
|
52
39
|
const webpackConfigs = await Promise.all(
|
|
53
40
|
targets.map((target) => (0, import_webpackConfig.generateWebpackConfig)({ target, context }))
|
package/dist/core/initHooks.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { OnExitFn, OnAfterBuildFn, OnBeforeBuildFn, OnDevCompileDoneFn, ModifyWebpackChainFn, ModifyWebpackConfigFn, ModifyRsbuildConfigFn, OnAfterStartDevServerFn, OnBeforeStartDevServerFn, OnAfterCreateCompilerFn, OnBeforeCreateCompilerFn } from '@rsbuild/shared';
|
|
1
|
+
import { OnExitFn, OnAfterBuildFn, OnBeforeBuildFn, OnDevCompileDoneFn, ModifyWebpackChainFn, ModifyWebpackConfigFn, ModifyRsbuildConfigFn, OnAfterStartDevServerFn, OnBeforeStartDevServerFn, OnAfterStartProdServerFn, OnBeforeStartProdServerFn, OnAfterCreateCompilerFn, OnBeforeCreateCompilerFn } from '@rsbuild/shared';
|
|
2
2
|
import type { ModifyBundlerChainFn } from '@rsbuild/shared';
|
|
3
|
-
import type { Compiler, MultiCompiler } from 'webpack';
|
|
4
3
|
import type { WebpackConfig, RsbuildConfig } from '../types';
|
|
5
4
|
export declare function initHooks(): {
|
|
6
5
|
onExitHook: import("@rsbuild/shared").AsyncHook<OnExitFn>;
|
|
@@ -10,10 +9,12 @@ export declare function initHooks(): {
|
|
|
10
9
|
modifyWebpackChainHook: import("@rsbuild/shared").AsyncHook<ModifyWebpackChainFn>;
|
|
11
10
|
modifyWebpackConfigHook: import("@rsbuild/shared").AsyncHook<ModifyWebpackConfigFn>;
|
|
12
11
|
modifyRsbuildConfigHook: import("@rsbuild/shared").AsyncHook<ModifyRsbuildConfigFn<RsbuildConfig>>;
|
|
13
|
-
onAfterCreateCompilerHook: import("@rsbuild/shared").AsyncHook<OnAfterCreateCompilerFn
|
|
12
|
+
onAfterCreateCompilerHook: import("@rsbuild/shared").AsyncHook<OnAfterCreateCompilerFn>;
|
|
14
13
|
onBeforeCreateCompilerHook: import("@rsbuild/shared").AsyncHook<OnBeforeCreateCompilerFn<WebpackConfig>>;
|
|
15
14
|
onAfterStartDevServerHook: import("@rsbuild/shared").AsyncHook<OnAfterStartDevServerFn>;
|
|
16
15
|
onBeforeStartDevServerHook: import("@rsbuild/shared").AsyncHook<OnBeforeStartDevServerFn>;
|
|
16
|
+
onAfterStartProdServerHook: import("@rsbuild/shared").AsyncHook<OnAfterStartProdServerFn>;
|
|
17
|
+
onBeforeStartProdServerHook: import("@rsbuild/shared").AsyncHook<OnBeforeStartProdServerFn>;
|
|
17
18
|
modifyBundlerChainHook: import("@rsbuild/shared").AsyncHook<ModifyBundlerChainFn>;
|
|
18
19
|
};
|
|
19
20
|
export type Hooks = ReturnType<typeof initHooks>;
|
package/dist/core/initHooks.js
CHANGED
|
@@ -35,6 +35,8 @@ function initHooks() {
|
|
|
35
35
|
onBeforeCreateCompilerHook: (0, import_shared.createAsyncHook)(),
|
|
36
36
|
onAfterStartDevServerHook: (0, import_shared.createAsyncHook)(),
|
|
37
37
|
onBeforeStartDevServerHook: (0, import_shared.createAsyncHook)(),
|
|
38
|
+
onAfterStartProdServerHook: (0, import_shared.createAsyncHook)(),
|
|
39
|
+
onBeforeStartProdServerHook: (0, import_shared.createAsyncHook)(),
|
|
38
40
|
modifyBundlerChainHook: (0, import_shared.createAsyncHook)()
|
|
39
41
|
};
|
|
40
42
|
}
|
package/dist/core/initPlugins.js
CHANGED
|
@@ -76,6 +76,8 @@ function getPluginAPI({
|
|
|
76
76
|
onBeforeCreateCompiler: hooks.onBeforeCreateCompilerHook.tap,
|
|
77
77
|
onAfterStartDevServer: hooks.onAfterStartDevServerHook.tap,
|
|
78
78
|
onBeforeStartDevServer: hooks.onBeforeStartDevServerHook.tap,
|
|
79
|
+
onAfterStartProdServer: hooks.onAfterStartProdServerHook.tap,
|
|
80
|
+
onBeforeStartProdServer: hooks.onBeforeStartProdServerHook.tap,
|
|
79
81
|
modifyRspackConfig: () => {
|
|
80
82
|
}
|
|
81
83
|
};
|
|
@@ -14,7 +14,17 @@ export declare function inspectConfig({
|
|
|
14
14
|
rsbuildConfig: string;
|
|
15
15
|
bundlerConfigs: string[];
|
|
16
16
|
origin: {
|
|
17
|
-
rsbuildConfig:
|
|
17
|
+
rsbuildConfig: {
|
|
18
|
+
pluginNames: string[];
|
|
19
|
+
dev?: import("@rsbuild/shared").DevConfig | undefined;
|
|
20
|
+
server?: import("@rsbuild/shared").ServerConfig | undefined;
|
|
21
|
+
html?: import("@rsbuild/shared").HtmlConfig | undefined;
|
|
22
|
+
tools?: import("../types").ToolsConfig | undefined;
|
|
23
|
+
source?: import("@rsbuild/shared").SourceConfig | undefined;
|
|
24
|
+
output?: import("@rsbuild/shared").OutputConfig | undefined;
|
|
25
|
+
security?: import("@rsbuild/shared").SecurityConfig | undefined;
|
|
26
|
+
performance?: import("@rsbuild/shared").PerformanceConfig | undefined;
|
|
27
|
+
};
|
|
18
28
|
bundlerConfigs: WebpackConfig[];
|
|
19
29
|
};
|
|
20
30
|
}>;
|
|
@@ -41,8 +41,12 @@ async function inspectConfig({
|
|
|
41
41
|
pluginStore,
|
|
42
42
|
rsbuildOptions
|
|
43
43
|
})).webpackConfigs;
|
|
44
|
+
const rsbuildDebugConfig = {
|
|
45
|
+
...context.config,
|
|
46
|
+
pluginNames: pluginStore.plugins.map((p) => p.name)
|
|
47
|
+
};
|
|
44
48
|
const rawRsbuildConfig = await (0, import_shared.stringifyConfig)(
|
|
45
|
-
|
|
49
|
+
rsbuildDebugConfig,
|
|
46
50
|
inspectOptions.verbose
|
|
47
51
|
);
|
|
48
52
|
const rawBundlerConfigs = await Promise.all(
|
|
@@ -70,7 +74,7 @@ async function inspectConfig({
|
|
|
70
74
|
rsbuildConfig: rawRsbuildConfig,
|
|
71
75
|
bundlerConfigs: rawBundlerConfigs,
|
|
72
76
|
origin: {
|
|
73
|
-
rsbuildConfig:
|
|
77
|
+
rsbuildConfig: rsbuildDebugConfig,
|
|
74
78
|
bundlerConfigs: webpackConfigs
|
|
75
79
|
}
|
|
76
80
|
};
|
|
@@ -34,13 +34,12 @@ module.exports = __toCommonJS(webpackConfig_exports);
|
|
|
34
34
|
var import_shared = require("@rsbuild/shared");
|
|
35
35
|
var import_shared2 = require("../shared");
|
|
36
36
|
async function modifyWebpackChain(context, utils, chain) {
|
|
37
|
-
var _a;
|
|
38
37
|
(0, import_shared.debug)("modify webpack chain");
|
|
39
38
|
const [modifiedChain] = await context.hooks.modifyWebpackChainHook.call(
|
|
40
39
|
chain,
|
|
41
40
|
utils
|
|
42
41
|
);
|
|
43
|
-
if (
|
|
42
|
+
if (context.config.tools?.webpackChain) {
|
|
44
43
|
(0, import_shared.castArray)(context.config.tools.webpackChain).forEach((item) => {
|
|
45
44
|
item(modifiedChain, utils);
|
|
46
45
|
});
|
|
@@ -49,13 +48,12 @@ async function modifyWebpackChain(context, utils, chain) {
|
|
|
49
48
|
return modifiedChain;
|
|
50
49
|
}
|
|
51
50
|
async function modifyWebpackConfig(context, webpackConfig, utils) {
|
|
52
|
-
var _a;
|
|
53
51
|
(0, import_shared.debug)("modify webpack config");
|
|
54
52
|
let [modifiedConfig] = await context.hooks.modifyWebpackConfigHook.call(
|
|
55
53
|
webpackConfig,
|
|
56
54
|
utils
|
|
57
55
|
);
|
|
58
|
-
if (
|
|
56
|
+
if (context.config.tools?.webpack) {
|
|
59
57
|
modifiedConfig = (0, import_shared.mergeChainedOptions)({
|
|
60
58
|
defaults: modifiedConfig,
|
|
61
59
|
options: context.config.tools.webpack,
|
|
@@ -123,7 +121,7 @@ async function getConfigUtils(config, chainUtils) {
|
|
|
123
121
|
removePlugin(pluginName) {
|
|
124
122
|
if (config.plugins) {
|
|
125
123
|
config.plugins = config.plugins.filter(
|
|
126
|
-
(item) =>
|
|
124
|
+
(item) => item?.constructor.name !== pluginName
|
|
127
125
|
);
|
|
128
126
|
}
|
|
129
127
|
}
|
|
@@ -134,13 +132,19 @@ async function generateWebpackConfig({
|
|
|
134
132
|
context
|
|
135
133
|
}) {
|
|
136
134
|
const chainUtils = await getChainUtils(target);
|
|
137
|
-
const {
|
|
135
|
+
const {
|
|
136
|
+
BannerPlugin,
|
|
137
|
+
DefinePlugin,
|
|
138
|
+
ProvidePlugin,
|
|
139
|
+
HotModuleReplacementPlugin
|
|
140
|
+
} = await Promise.resolve().then(() => __toESM(require("webpack")));
|
|
138
141
|
const bundlerChain = await (0, import_shared.modifyBundlerChain)(context, {
|
|
139
142
|
...chainUtils,
|
|
140
143
|
bundler: {
|
|
141
144
|
BannerPlugin,
|
|
142
145
|
DefinePlugin,
|
|
143
|
-
ProvidePlugin
|
|
146
|
+
ProvidePlugin,
|
|
147
|
+
HotModuleReplacementPlugin
|
|
144
148
|
}
|
|
145
149
|
});
|
|
146
150
|
const chain = await modifyWebpackChain(
|
package/dist/plugins/babel.d.ts
CHANGED
package/dist/plugins/babel.js
CHANGED
|
@@ -28,7 +28,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var babel_exports = {};
|
|
30
30
|
__export(babel_exports, {
|
|
31
|
-
getUseBuiltIns: () => getUseBuiltIns,
|
|
32
31
|
pluginBabel: () => pluginBabel
|
|
33
32
|
});
|
|
34
33
|
module.exports = __toCommonJS(babel_exports);
|
|
@@ -38,13 +37,6 @@ var import_node = require("@rsbuild/babel-preset/node");
|
|
|
38
37
|
var import_shared = require("@rsbuild/shared");
|
|
39
38
|
var import_plugin_babel = require("@rsbuild/plugin-babel");
|
|
40
39
|
var import_shared2 = require("../shared");
|
|
41
|
-
const getUseBuiltIns = (config) => {
|
|
42
|
-
const { polyfill } = config.output;
|
|
43
|
-
if (polyfill === "ua" || polyfill === "off") {
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
return polyfill;
|
|
47
|
-
};
|
|
48
40
|
const pluginBabel = () => ({
|
|
49
41
|
name: "rsbuild-webpack:babel",
|
|
50
42
|
setup(api) {
|
|
@@ -83,7 +75,7 @@ const pluginBabel = () => ({
|
|
|
83
75
|
}) : (0, import_web.getBabelConfigForWeb)({
|
|
84
76
|
presetEnv: {
|
|
85
77
|
targets: browserslist,
|
|
86
|
-
useBuiltIns: getUseBuiltIns(config2)
|
|
78
|
+
useBuiltIns: (0, import_plugin_babel.getUseBuiltIns)(config2)
|
|
87
79
|
},
|
|
88
80
|
pluginDecorators: decoratorConfig
|
|
89
81
|
});
|
|
@@ -118,7 +110,6 @@ const pluginBabel = () => ({
|
|
|
118
110
|
};
|
|
119
111
|
};
|
|
120
112
|
const { babelOptions, includes, excludes } = getBabelOptions(config);
|
|
121
|
-
const useTsLoader = Boolean(config.tools.tsLoader);
|
|
122
113
|
const rule = chain.module.rule(CHAIN_ID.RULE.JS);
|
|
123
114
|
(0, import_shared.applyScriptCondition)({
|
|
124
115
|
rule,
|
|
@@ -127,7 +118,7 @@ const pluginBabel = () => ({
|
|
|
127
118
|
includes,
|
|
128
119
|
excludes
|
|
129
120
|
});
|
|
130
|
-
rule.test(
|
|
121
|
+
rule.test(import_shared.SCRIPT_REGEX).use(CHAIN_ID.USE.BABEL).loader(require.resolve("babel-loader")).options(babelOptions);
|
|
131
122
|
chain.module.rule(CHAIN_ID.RULE.JS_DATA_URI).mimetype({
|
|
132
123
|
or: ["text/javascript", "application/javascript"]
|
|
133
124
|
}).use(CHAIN_ID.USE.BABEL).loader(require.resolve("babel-loader")).options(import_lodash.default.cloneDeep(babelOptions));
|
|
@@ -137,13 +128,11 @@ const pluginBabel = () => ({
|
|
|
137
128
|
}
|
|
138
129
|
});
|
|
139
130
|
function applyPluginLodash(config, transformLodash) {
|
|
140
|
-
var _a;
|
|
141
131
|
if (transformLodash) {
|
|
142
|
-
|
|
132
|
+
config.plugins?.push([(0, import_shared2.getCompiledPath)("babel-plugin-lodash"), {}]);
|
|
143
133
|
}
|
|
144
134
|
}
|
|
145
135
|
function applyPluginImport(config, pluginImport) {
|
|
146
|
-
var _a, _b;
|
|
147
136
|
if (pluginImport !== false && pluginImport) {
|
|
148
137
|
for (const item of pluginImport) {
|
|
149
138
|
const name = item.libraryName;
|
|
@@ -151,10 +140,10 @@ function applyPluginImport(config, pluginImport) {
|
|
|
151
140
|
...item
|
|
152
141
|
};
|
|
153
142
|
if (option.camelToDashComponentName !== void 0 || option.camel2DashComponentName !== void 0) {
|
|
154
|
-
option.camel2DashComponentName =
|
|
143
|
+
option.camel2DashComponentName = option.camel2DashComponentName ?? option.camelToDashComponentName;
|
|
155
144
|
delete option.camelToDashComponentName;
|
|
156
145
|
}
|
|
157
|
-
|
|
146
|
+
config.plugins?.push([
|
|
158
147
|
require.resolve("babel-plugin-import"),
|
|
159
148
|
option,
|
|
160
149
|
name
|
|
@@ -164,6 +153,5 @@ function applyPluginImport(config, pluginImport) {
|
|
|
164
153
|
}
|
|
165
154
|
// Annotate the CommonJS export names for ESM import in node:
|
|
166
155
|
0 && (module.exports = {
|
|
167
|
-
getUseBuiltIns,
|
|
168
156
|
pluginBabel
|
|
169
157
|
});
|
package/dist/plugins/basic.js
CHANGED
|
@@ -37,7 +37,7 @@ const pluginBasic = () => ({
|
|
|
37
37
|
name: "rsbuild-webpack:basic",
|
|
38
38
|
setup(api) {
|
|
39
39
|
(0, import_shared.applyBasicPlugin)(api);
|
|
40
|
-
api.
|
|
40
|
+
api.modifyBundlerChain(async (chain, { env }) => {
|
|
41
41
|
chain.performance.hints(false);
|
|
42
42
|
chain.module.parser.merge({
|
|
43
43
|
javascript: {
|
package/dist/plugins/copy.js
CHANGED
|
@@ -35,7 +35,7 @@ var import_fs = __toESM(require("fs"));
|
|
|
35
35
|
const pluginCopy = () => ({
|
|
36
36
|
name: "rsbuild-webpack:copy",
|
|
37
37
|
setup(api) {
|
|
38
|
-
api.
|
|
38
|
+
api.modifyBundlerChain(async (chain, { CHAIN_ID }) => {
|
|
39
39
|
const config = api.getNormalizedConfig();
|
|
40
40
|
const { copy } = config.output;
|
|
41
41
|
if (!copy) {
|
|
@@ -46,17 +46,16 @@ const pluginCopy = () => ({
|
|
|
46
46
|
chain.plugin(CHAIN_ID.PLUGIN.COPY).use(CopyPlugin, [options]);
|
|
47
47
|
});
|
|
48
48
|
api.modifyWebpackConfig(async (config) => {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
(item) => (item == null ? void 0 : item.constructor.name) === "CopyPlugin"
|
|
49
|
+
const copyPlugin = config.plugins?.find(
|
|
50
|
+
(item) => item?.constructor.name === "CopyPlugin"
|
|
52
51
|
);
|
|
53
52
|
if (copyPlugin) {
|
|
54
53
|
const isContextNotExists = copyPlugin.patterns.every(
|
|
55
54
|
(pattern) => typeof pattern !== "string" && pattern.context && !import_fs.default.existsSync(pattern.context)
|
|
56
55
|
);
|
|
57
56
|
if (isContextNotExists) {
|
|
58
|
-
config.plugins =
|
|
59
|
-
(item) =>
|
|
57
|
+
config.plugins = config.plugins?.filter(
|
|
58
|
+
(item) => item?.constructor.name !== "CopyPlugin"
|
|
60
59
|
);
|
|
61
60
|
}
|
|
62
61
|
}
|
package/dist/plugins/hmr.js
CHANGED
|
@@ -25,13 +25,13 @@ var import_shared = require("@rsbuild/shared");
|
|
|
25
25
|
const pluginHMR = () => ({
|
|
26
26
|
name: "rsbuild-webpack:hmr",
|
|
27
27
|
setup(api) {
|
|
28
|
-
api.
|
|
28
|
+
api.modifyBundlerChain((chain, utils) => {
|
|
29
29
|
const config = api.getNormalizedConfig();
|
|
30
30
|
if (!(0, import_shared.isUsingHMR)(config, utils)) {
|
|
31
31
|
return;
|
|
32
32
|
}
|
|
33
|
-
const {
|
|
34
|
-
chain.plugin(CHAIN_ID.PLUGIN.HMR).use(
|
|
33
|
+
const { bundler, CHAIN_ID } = utils;
|
|
34
|
+
chain.plugin(CHAIN_ID.PLUGIN.HMR).use(bundler.HotModuleReplacementPlugin);
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
});
|
package/dist/plugins/output.js
CHANGED
|
@@ -37,15 +37,14 @@ const pluginOutput = () => ({
|
|
|
37
37
|
name: "rsbuild-webpack:output",
|
|
38
38
|
setup(api) {
|
|
39
39
|
(0, import_shared.applyOutputPlugin)(api);
|
|
40
|
-
api.
|
|
41
|
-
var _a;
|
|
40
|
+
api.modifyBundlerChain(async (chain, { isProd, target, CHAIN_ID }) => {
|
|
42
41
|
const config = api.getNormalizedConfig();
|
|
43
42
|
const cssPath = (0, import_shared.getDistPath)(config.output, "css");
|
|
44
43
|
if ((0, import_shared.isUseCssExtract)(config, target)) {
|
|
45
44
|
const { default: MiniCssExtractPlugin } = await Promise.resolve().then(() => __toESM(require("mini-css-extract-plugin")));
|
|
46
45
|
const extractPluginOptions = (0, import_shared.mergeChainedOptions)({
|
|
47
46
|
defaults: {},
|
|
48
|
-
options:
|
|
47
|
+
options: config.tools.cssExtract?.pluginOptions
|
|
49
48
|
});
|
|
50
49
|
const cssFilename = (0, import_shared.getFilename)(config.output, "css", isProd);
|
|
51
50
|
chain.plugin(CHAIN_ID.PLUGIN.MINI_CSS_EXTRACT).use(MiniCssExtractPlugin, [
|
package/dist/plugins/progress.js
CHANGED
|
@@ -35,10 +35,9 @@ var import_shared = require("@rsbuild/shared");
|
|
|
35
35
|
const pluginProgress = () => ({
|
|
36
36
|
name: "rsbuild-webpack:progress",
|
|
37
37
|
setup(api) {
|
|
38
|
-
api.
|
|
39
|
-
var _a;
|
|
38
|
+
api.modifyBundlerChain(async (chain, { target, CHAIN_ID }) => {
|
|
40
39
|
const config = api.getNormalizedConfig();
|
|
41
|
-
const options =
|
|
40
|
+
const options = config.dev.progressBar ?? true;
|
|
42
41
|
if (!options) {
|
|
43
42
|
return;
|
|
44
43
|
}
|
package/dist/plugins/react.js
CHANGED
|
@@ -35,6 +35,7 @@ var import_plugin_react = require("@rsbuild/plugin-react");
|
|
|
35
35
|
var import_shared = require("@rsbuild/shared");
|
|
36
36
|
const pluginReactWebpack = () => ({
|
|
37
37
|
name: "rsbuild-webpack:react",
|
|
38
|
+
pre: ["rsbuild-webpack:babel"],
|
|
38
39
|
setup(api) {
|
|
39
40
|
api.modifyRsbuildConfig(async (config, { mergeRsbuildConfig }) => {
|
|
40
41
|
const isNewJsx = await (0, import_plugin_react.isBeyondReact17)(api.context.rootPath);
|
|
@@ -64,16 +65,21 @@ const pluginReactWebpack = () => ({
|
|
|
64
65
|
};
|
|
65
66
|
return mergeRsbuildConfig(babelConfig, config);
|
|
66
67
|
});
|
|
67
|
-
api.
|
|
68
|
+
api.modifyBundlerChain(async (chain, utils) => {
|
|
68
69
|
const config = api.getNormalizedConfig();
|
|
69
70
|
if (!(0, import_shared.isUsingHMR)(config, utils)) {
|
|
70
71
|
return;
|
|
71
72
|
}
|
|
72
73
|
const { CHAIN_ID } = utils;
|
|
73
74
|
const { default: ReactFastRefreshPlugin } = await Promise.resolve().then(() => __toESM(require("@pmmmwh/react-refresh-webpack-plugin")));
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
[CHAIN_ID.RULE.TS, CHAIN_ID.RULE.JS].forEach((ruleId) => {
|
|
76
|
+
if (!chain.module.rules.get(ruleId)) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const rule = chain.module.rule(ruleId);
|
|
80
|
+
if (!rule.uses.get(CHAIN_ID.USE.BABEL)) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
77
83
|
rule.use(CHAIN_ID.USE.BABEL).tap((options) => ({
|
|
78
84
|
...options,
|
|
79
85
|
plugins: [
|
|
@@ -81,7 +87,7 @@ const pluginReactWebpack = () => ({
|
|
|
81
87
|
[require.resolve("react-refresh/babel"), { skipEnvCheck: true }]
|
|
82
88
|
]
|
|
83
89
|
}));
|
|
84
|
-
}
|
|
90
|
+
});
|
|
85
91
|
chain.plugin(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH).use(ReactFastRefreshPlugin, [
|
|
86
92
|
{
|
|
87
93
|
overlay: false,
|
package/dist/plugins/resolve.js
CHANGED
|
@@ -64,7 +64,7 @@ const pluginResolve = () => ({
|
|
|
64
64
|
name: "rsbuild-webpack:resolve",
|
|
65
65
|
setup(api) {
|
|
66
66
|
(0, import_shared.applyResolvePlugin)(api);
|
|
67
|
-
api.
|
|
67
|
+
api.modifyBundlerChain(async (chain, { CHAIN_ID, target }) => {
|
|
68
68
|
const config = api.getNormalizedConfig();
|
|
69
69
|
const isTsProject = Boolean(api.context.tsconfigPath);
|
|
70
70
|
chain.module.rule(CHAIN_ID.RULE.JS_DATA_URI).resolve.set("fullySpecified", false);
|
package/dist/provider.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { type RsbuildProvider } from '@rsbuild/shared';
|
|
2
2
|
import { RsbuildConfig, NormalizedConfig, WebpackConfig } from './types';
|
|
3
|
-
|
|
4
|
-
export type WebpackProvider = RsbuildProvider<RsbuildConfig, WebpackConfig, NormalizedConfig, Compiler | MultiCompiler>;
|
|
3
|
+
export type WebpackProvider = RsbuildProvider<RsbuildConfig, WebpackConfig, NormalizedConfig>;
|
|
5
4
|
export declare function webpackProvider({
|
|
6
5
|
rsbuildConfig: originalRsbuildConfig
|
|
7
6
|
}: {
|
package/dist/provider.js
CHANGED
|
@@ -32,7 +32,6 @@ __export(provider_exports, {
|
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(provider_exports);
|
|
34
34
|
var import_shared = require("@rsbuild/shared");
|
|
35
|
-
var import_server = require("@rsbuild/core/server");
|
|
36
35
|
var import_rspack_provider = require("@rsbuild/core/rspack-provider");
|
|
37
36
|
var import_createContext = require("./core/createContext");
|
|
38
37
|
var import_plugin = require("./shared/plugin");
|
|
@@ -71,16 +70,37 @@ function webpackProvider({
|
|
|
71
70
|
return createCompiler({ context, webpackConfigs });
|
|
72
71
|
},
|
|
73
72
|
async startDevServer(options) {
|
|
73
|
+
const { startDevServer } = await Promise.resolve().then(() => __toESM(require("@rsbuild/core/server")));
|
|
74
74
|
const { createDevMiddleware } = await Promise.resolve().then(() => __toESM(require("./core/createCompiler")));
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
await (0, import_rspack_provider.initRsbuildConfig)({
|
|
76
|
+
// @ts-expect-error context type mismatch
|
|
77
|
+
context,
|
|
78
|
+
pluginStore
|
|
79
|
+
});
|
|
80
|
+
return startDevServer(
|
|
81
|
+
{
|
|
82
|
+
// @ts-expect-error context type mismatch
|
|
83
|
+
context,
|
|
84
|
+
pluginStore,
|
|
85
|
+
rsbuildOptions
|
|
86
|
+
},
|
|
78
87
|
createDevMiddleware,
|
|
79
88
|
options
|
|
80
89
|
);
|
|
81
90
|
},
|
|
82
91
|
async preview(options) {
|
|
83
|
-
|
|
92
|
+
const { startProdServer } = await Promise.resolve().then(() => __toESM(require("@rsbuild/core/server")));
|
|
93
|
+
await (0, import_rspack_provider.initRsbuildConfig)({
|
|
94
|
+
// @ts-expect-error context type mismatch
|
|
95
|
+
context,
|
|
96
|
+
pluginStore
|
|
97
|
+
});
|
|
98
|
+
return startProdServer(
|
|
99
|
+
// @ts-expect-error context type mismatch
|
|
100
|
+
context,
|
|
101
|
+
context.config,
|
|
102
|
+
options
|
|
103
|
+
);
|
|
84
104
|
},
|
|
85
105
|
async build(options) {
|
|
86
106
|
const { build: buildImpl, webpackBuild } = await Promise.resolve().then(() => __toESM(require("./core/build")));
|
package/dist/shared/plugin.js
CHANGED
|
@@ -32,46 +32,42 @@ __export(plugin_exports, {
|
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(plugin_exports);
|
|
34
34
|
var import_shared = require("@rsbuild/shared");
|
|
35
|
-
const applyDefaultPlugins = (plugins) =>
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
plugins.networkPerformance(),
|
|
72
|
-
plugins.preloadOrPrefetch()
|
|
73
|
-
]);
|
|
74
|
-
};
|
|
35
|
+
const applyDefaultPlugins = (plugins) => (0, import_shared.awaitableGetter)([
|
|
36
|
+
Promise.resolve().then(() => __toESM(require("../plugins/basic"))).then((m) => m.pluginBasic()),
|
|
37
|
+
plugins.entry?.(),
|
|
38
|
+
plugins.cache?.(),
|
|
39
|
+
plugins.target?.(),
|
|
40
|
+
Promise.resolve().then(() => __toESM(require("../plugins/output"))).then((m) => m.pluginOutput()),
|
|
41
|
+
plugins.devtool(),
|
|
42
|
+
Promise.resolve().then(() => __toESM(require("../plugins/resolve"))).then((m) => m.pluginResolve()),
|
|
43
|
+
plugins.fileSize?.(),
|
|
44
|
+
plugins.cleanOutput?.(),
|
|
45
|
+
Promise.resolve().then(() => __toESM(require("../plugins/hmr"))).then((m) => m.pluginHMR()),
|
|
46
|
+
plugins.asset(),
|
|
47
|
+
Promise.resolve().then(() => __toESM(require("../plugins/copy"))).then((m) => m.pluginCopy()),
|
|
48
|
+
plugins.html(),
|
|
49
|
+
plugins.wasm(),
|
|
50
|
+
plugins.moment(),
|
|
51
|
+
plugins.nodeAddons(),
|
|
52
|
+
plugins.define(),
|
|
53
|
+
Promise.resolve().then(() => __toESM(require("../plugins/progress"))).then((m) => m.pluginProgress()),
|
|
54
|
+
Promise.resolve().then(() => __toESM(require("../plugins/minimize"))).then((m) => m.pluginMinimize()),
|
|
55
|
+
Promise.resolve().then(() => __toESM(require("../plugins/babel"))).then((m) => m.pluginBabel()),
|
|
56
|
+
Promise.resolve().then(() => __toESM(require("../plugins/react"))).then((m) => m.pluginReactWebpack()),
|
|
57
|
+
Promise.resolve().then(() => __toESM(require("../plugins/css"))).then((m) => m.pluginCss()),
|
|
58
|
+
Promise.resolve().then(() => __toESM(require("../plugins/sass"))).then((m) => m.pluginSass()),
|
|
59
|
+
Promise.resolve().then(() => __toESM(require("../plugins/less"))).then((m) => m.pluginLess()),
|
|
60
|
+
plugins.bundleAnalyzer(),
|
|
61
|
+
plugins.toml(),
|
|
62
|
+
plugins.yaml(),
|
|
63
|
+
plugins.splitChunks(),
|
|
64
|
+
plugins.startUrl?.(),
|
|
65
|
+
plugins.inlineChunk(),
|
|
66
|
+
plugins.externals(),
|
|
67
|
+
plugins.performance(),
|
|
68
|
+
plugins.networkPerformance(),
|
|
69
|
+
plugins.preloadOrPrefetch()
|
|
70
|
+
]);
|
|
75
71
|
// Annotate the CommonJS export names for ESM import in node:
|
|
76
72
|
0 && (module.exports = {
|
|
77
73
|
applyDefaultPlugins
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import type { ArrayOrNot, ChainedConfig,
|
|
1
|
+
import type { ArrayOrNot, ChainedConfig, TerserPluginOptions, ToolsConfig as BaseToolsConfig, ChainedConfigWithUtils, ModifyWebpackChainUtils, ModifyWebpackConfigUtils } from '@rsbuild/shared';
|
|
2
2
|
import type { BabelTransformOptions, BabelConfigUtils } from '@rsbuild/plugin-babel';
|
|
3
3
|
import type { PluginCssMinimizerOptions } from '@rsbuild/plugin-css-minimizer';
|
|
4
|
-
import type { WebpackChain, WebpackConfig,
|
|
4
|
+
import type { WebpackChain, WebpackConfig, CSSExtractOptions } from '../thirdParty';
|
|
5
5
|
import type { NormalizedCSSExtractOptions } from '../thirdParty/css';
|
|
6
6
|
export type ToolsTerserConfig = ChainedConfig<TerserPluginOptions>;
|
|
7
|
-
export type ToolsTSLoaderConfig = ChainedConfigWithUtils<TSLoaderOptions, {
|
|
8
|
-
addIncludes: FileFilterUtil;
|
|
9
|
-
addExcludes: FileFilterUtil;
|
|
10
|
-
}>;
|
|
11
7
|
export type ToolsCssExtractConfig = CSSExtractOptions | ((options: CSSExtractOptions) => CSSExtractOptions | void);
|
|
12
8
|
export type ToolsWebpackConfig = ChainedConfigWithUtils<WebpackConfig, ModifyWebpackConfigUtils>;
|
|
13
9
|
export type ToolsWebpackChainConfig = ArrayOrNot<(chain: WebpackChain, utils: ModifyWebpackChainUtils) => void>;
|
|
@@ -24,11 +20,6 @@ export interface ToolsConfig extends BaseToolsConfig {
|
|
|
24
20
|
* Modify the options of [terser-webpack-plugin](https://github.com/webpack-contrib/terser-webpack-plugin).
|
|
25
21
|
*/
|
|
26
22
|
terser?: ToolsTerserConfig;
|
|
27
|
-
/**
|
|
28
|
-
* Modify the options of [ts-loader](https://github.com/TypeStrong/ts-loader).
|
|
29
|
-
* When `tools.tsLoader` is not undefined, Rsbuild will use ts-loader instead of babel-loader to compile TypeScript code.
|
|
30
|
-
*/
|
|
31
|
-
tsLoader?: ToolsTSLoaderConfig;
|
|
32
23
|
/**
|
|
33
24
|
* Modify the options of [mini-css-extract-plugin](https://github.com/webpack-contrib/mini-css-extract-plugin).
|
|
34
25
|
*/
|
package/dist/types/plugin.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { DefaultRsbuildPluginAPI, RsbuildPlugin as BaseRsbuildPlugin } from '@rsbuild/shared';
|
|
2
|
-
import type { Compiler, MultiCompiler } from 'webpack';
|
|
3
2
|
import type { RsbuildConfig, NormalizedConfig } from './config';
|
|
4
3
|
import type { WebpackConfig } from './thirdParty';
|
|
5
|
-
export interface RsbuildPluginAPI extends DefaultRsbuildPluginAPI<RsbuildConfig, NormalizedConfig, WebpackConfig
|
|
4
|
+
export interface RsbuildPluginAPI extends DefaultRsbuildPluginAPI<RsbuildConfig, NormalizedConfig, WebpackConfig> {}
|
|
6
5
|
export type RsbuildPlugin = BaseRsbuildPlugin<RsbuildPluginAPI>;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { WebpackChain } from '@rsbuild/shared';
|
|
2
2
|
import type webpack from 'webpack';
|
|
3
3
|
import type { Configuration as WebpackConfig } from 'webpack';
|
|
4
|
-
import type { Options as RawTSLoaderOptions } from 'ts-loader';
|
|
5
4
|
export type { Options as HTMLPluginOptions } from 'html-webpack-plugin';
|
|
6
|
-
export type TSLoaderOptions = Partial<RawTSLoaderOptions>;
|
|
7
5
|
export type { webpack, WebpackChain, WebpackConfig };
|
|
8
6
|
export type { CSSExtractOptions, MiniCSSExtractPluginOptions, MiniCSSExtractLoaderOptions } from './css';
|
|
@@ -68,16 +68,12 @@ class Bus {
|
|
|
68
68
|
this.log(this.prevOutput);
|
|
69
69
|
}
|
|
70
70
|
render() {
|
|
71
|
-
const maxIdLen = Math.max(...this.states.map((i) =>
|
|
72
|
-
var _a, _b;
|
|
73
|
-
return (_b = (_a = i.id) == null ? void 0 : _a.length) != null ? _b : 0;
|
|
74
|
-
})) + 2;
|
|
71
|
+
const maxIdLen = Math.max(...this.states.map((i) => i.id?.length ?? 0)) + 2;
|
|
75
72
|
const { columns = import_bar.FULL_WIDTH } = process.stdout;
|
|
76
73
|
this.prevOutput = this.states.map((i, k) => {
|
|
77
|
-
var _a;
|
|
78
74
|
const bar = (0, import_bar.renderBar)({
|
|
79
75
|
maxIdLen,
|
|
80
|
-
color:
|
|
76
|
+
color: i.color ?? (0, import_shared.getProgressColor)(k),
|
|
81
77
|
...i
|
|
82
78
|
});
|
|
83
79
|
if (bar) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/webpack",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"homepage": "https://rsbuild.dev",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -48,15 +48,14 @@
|
|
|
48
48
|
"react-refresh": "^0.14.0",
|
|
49
49
|
"style-loader": "3.3.3",
|
|
50
50
|
"terser-webpack-plugin": "5.3.9",
|
|
51
|
-
"ts-loader": "9.4.4",
|
|
52
51
|
"tsconfig-paths-webpack-plugin": "4.1.0",
|
|
53
52
|
"webpack": "^5.89.0",
|
|
54
|
-
"@rsbuild/babel-preset": "0.1.
|
|
55
|
-
"@rsbuild/core": "0.1.
|
|
56
|
-
"@rsbuild/plugin-babel": "0.1.
|
|
57
|
-
"@rsbuild/plugin-
|
|
58
|
-
"@rsbuild/plugin-
|
|
59
|
-
"@rsbuild/shared": "0.1.
|
|
53
|
+
"@rsbuild/babel-preset": "0.1.3",
|
|
54
|
+
"@rsbuild/core": "0.1.3",
|
|
55
|
+
"@rsbuild/plugin-babel": "0.1.3",
|
|
56
|
+
"@rsbuild/plugin-react": "0.1.3",
|
|
57
|
+
"@rsbuild/plugin-css-minimizer": "0.1.3",
|
|
58
|
+
"@rsbuild/shared": "0.1.3"
|
|
60
59
|
},
|
|
61
60
|
"devDependencies": {
|
|
62
61
|
"@types/lodash": "^4.14.200",
|
|
@@ -64,7 +63,7 @@
|
|
|
64
63
|
"react": "^18.2.0",
|
|
65
64
|
"react-dom": "^18.2.0",
|
|
66
65
|
"typescript": "^5.3.0",
|
|
67
|
-
"@rsbuild/test-helper": "0.1.
|
|
66
|
+
"@rsbuild/test-helper": "0.1.3"
|
|
68
67
|
},
|
|
69
68
|
"engines": {
|
|
70
69
|
"node": ">=14.0.0"
|
package/dist/plugins/tsLoader.js
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
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;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var tsLoader_exports = {};
|
|
30
|
-
__export(tsLoader_exports, {
|
|
31
|
-
pluginTsLoader: () => pluginTsLoader
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(tsLoader_exports);
|
|
34
|
-
var import_shared = require("@rsbuild/shared");
|
|
35
|
-
var import_plugin_babel = require("@rsbuild/plugin-babel");
|
|
36
|
-
var import_web = require("@rsbuild/babel-preset/web");
|
|
37
|
-
var import_babel = require("./babel");
|
|
38
|
-
const pluginTsLoader = () => {
|
|
39
|
-
return {
|
|
40
|
-
name: "rsbuild-webpack:ts-loader",
|
|
41
|
-
setup(api) {
|
|
42
|
-
api.modifyWebpackChain(async (chain, { target, CHAIN_ID }) => {
|
|
43
|
-
const config = api.getNormalizedConfig();
|
|
44
|
-
if (!config.tools.tsLoader) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
const { rootPath } = api.context;
|
|
48
|
-
const browserslist = await (0, import_shared.getBrowserslistWithDefault)(
|
|
49
|
-
rootPath,
|
|
50
|
-
config,
|
|
51
|
-
target
|
|
52
|
-
);
|
|
53
|
-
const baseBabelConfig = (0, import_web.getBabelConfigForWeb)({
|
|
54
|
-
presetEnv: {
|
|
55
|
-
targets: browserslist,
|
|
56
|
-
useBuiltIns: (0, import_babel.getUseBuiltIns)(config)
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
const babelUtils = (0, import_plugin_babel.getBabelUtils)(baseBabelConfig);
|
|
60
|
-
const babelLoaderOptions = (0, import_shared.mergeChainedOptions)({
|
|
61
|
-
defaults: baseBabelConfig,
|
|
62
|
-
options: config.tools.babel,
|
|
63
|
-
utils: babelUtils
|
|
64
|
-
});
|
|
65
|
-
const includes = [];
|
|
66
|
-
const excludes = [];
|
|
67
|
-
const tsLoaderUtils = {
|
|
68
|
-
addIncludes(items) {
|
|
69
|
-
includes.push(...(0, import_shared.castArray)(items));
|
|
70
|
-
},
|
|
71
|
-
addExcludes(items) {
|
|
72
|
-
excludes.push(...(0, import_shared.castArray)(items));
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
const tsLoaderDefaultOptions = {
|
|
76
|
-
compilerOptions: {
|
|
77
|
-
target: "esnext",
|
|
78
|
-
module: "esnext"
|
|
79
|
-
},
|
|
80
|
-
transpileOnly: true,
|
|
81
|
-
allowTsInNodeModules: true
|
|
82
|
-
};
|
|
83
|
-
const tsLoaderOptions = (0, import_shared.mergeChainedOptions)({
|
|
84
|
-
defaults: tsLoaderDefaultOptions,
|
|
85
|
-
// @ts-expect-error ts-loader has incorrect types for compilerOptions
|
|
86
|
-
options: config.tools.tsLoader,
|
|
87
|
-
utils: tsLoaderUtils
|
|
88
|
-
});
|
|
89
|
-
const rule = chain.module.rule(CHAIN_ID.RULE.TS);
|
|
90
|
-
(0, import_shared.applyScriptCondition)({
|
|
91
|
-
rule,
|
|
92
|
-
config,
|
|
93
|
-
context: api.context,
|
|
94
|
-
includes,
|
|
95
|
-
excludes
|
|
96
|
-
});
|
|
97
|
-
rule.test(import_shared.TS_REGEX).use(CHAIN_ID.USE.BABEL).loader(require.resolve("babel-loader")).options(babelLoaderOptions).end().use(CHAIN_ID.USE.TS).loader(require.resolve("ts-loader")).options(tsLoaderOptions);
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
};
|
|
102
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
103
|
-
0 && (module.exports = {
|
|
104
|
-
pluginTsLoader
|
|
105
|
-
});
|