@rsbuild/webpack 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/dist/build.d.ts +3 -0
- package/dist/createCompiler.d.ts +12 -0
- package/dist/index.cjs +107 -87
- package/dist/index.d.ts +2 -6
- package/dist/index.js +91 -75
- package/dist/initConfigs.d.ts +12 -0
- package/dist/inspectConfig.d.ts +7 -0
- package/dist/plugin.d.ts +5 -0
- package/dist/progress/ProgressPlugin.d.ts +13 -0
- package/dist/progress/helpers/bar.d.ts +5 -0
- package/dist/progress/helpers/bus.d.ts +19 -0
- package/dist/progress/helpers/index.d.ts +4 -0
- package/dist/progress/helpers/log.d.ts +8 -0
- package/dist/progress/helpers/nonTty.d.ts +9 -0
- package/dist/progress/helpers/percentage.d.ts +7 -0
- package/dist/progress/helpers/type.d.ts +23 -0
- package/dist/progress/helpers/utils.d.ts +1 -0
- package/dist/provider.d.ts +2 -0
- package/dist/shared.d.ts +16 -0
- package/dist/types.d.ts +3 -0
- package/dist/webpackConfig.d.ts +8 -0
- package/package.json +8 -7
package/dist/build.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Rspack } from '@rsbuild/core';
|
|
2
|
+
import { type InitConfigsOptions } from './initConfigs';
|
|
3
|
+
import { type InternalContext } from './shared';
|
|
4
|
+
import type { WebpackConfig } from './types';
|
|
5
|
+
export declare function createCompiler({ context, webpackConfigs, }: {
|
|
6
|
+
context: InternalContext;
|
|
7
|
+
webpackConfigs: WebpackConfig[];
|
|
8
|
+
}): Promise<Rspack.Compiler | Rspack.MultiCompiler>;
|
|
9
|
+
export declare function createDevMiddleware(options: InitConfigsOptions, customCompiler?: Rspack.Compiler | Rspack.MultiCompiler): Promise<{
|
|
10
|
+
devMiddleware: import("node_modules/@rsbuild/core/dist-types/server/devMiddleware").DevMiddleware;
|
|
11
|
+
compiler: Rspack.Compiler | Rspack.MultiCompiler;
|
|
12
|
+
}>;
|
package/dist/index.cjs
CHANGED
|
@@ -39,7 +39,7 @@ var __publicField = (obj, key, value) => {
|
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
// src/shared.ts
|
|
42
|
-
var import_core, getChainUtils, initRsbuildConfig, createDevServer, formatStats, getDevMiddleware, getStatsOptions, stringifyConfig, outputInspectConfigFiles, chainToConfig, modifyBundlerChain, onCompileDone,
|
|
42
|
+
var import_core, getChainUtils, initRsbuildConfig, createDevServer, formatStats, getDevMiddleware, getStatsOptions, stringifyConfig, outputInspectConfigFiles, getRsbuildInspectConfig, chainToConfig, modifyBundlerChain, onCompileDone, prettyTime;
|
|
43
43
|
var init_shared = __esm({
|
|
44
44
|
"src/shared.ts"() {
|
|
45
45
|
"use strict";
|
|
@@ -53,10 +53,11 @@ var init_shared = __esm({
|
|
|
53
53
|
getStatsOptions,
|
|
54
54
|
stringifyConfig,
|
|
55
55
|
outputInspectConfigFiles,
|
|
56
|
+
getRsbuildInspectConfig,
|
|
56
57
|
chainToConfig,
|
|
57
58
|
modifyBundlerChain,
|
|
58
59
|
onCompileDone,
|
|
59
|
-
|
|
60
|
+
prettyTime
|
|
60
61
|
} = import_core.__internalHelper);
|
|
61
62
|
}
|
|
62
63
|
});
|
|
@@ -74,37 +75,37 @@ async function inspectConfig({
|
|
|
74
75
|
inspectOptions = {}
|
|
75
76
|
}) {
|
|
76
77
|
if (inspectOptions.env) {
|
|
77
|
-
|
|
78
|
-
} else if (!
|
|
79
|
-
|
|
78
|
+
process.env.NODE_ENV = inspectOptions.env;
|
|
79
|
+
} else if (!process.env.NODE_ENV) {
|
|
80
|
+
process.env.NODE_ENV = "development";
|
|
80
81
|
}
|
|
81
82
|
const webpackConfigs = bundlerConfigs || (await initConfigs({
|
|
82
83
|
context,
|
|
83
84
|
pluginManager,
|
|
84
85
|
rsbuildOptions
|
|
85
86
|
})).webpackConfigs;
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
};
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
87
|
+
const rawBundlerConfigs = webpackConfigs.map((config, index) => ({
|
|
88
|
+
name: config.name || String(index),
|
|
89
|
+
content: stringifyConfig(config, inspectOptions.verbose)
|
|
90
|
+
}));
|
|
91
|
+
const {
|
|
92
|
+
rsbuildConfig,
|
|
93
|
+
rawRsbuildConfig,
|
|
94
|
+
environmentConfigs,
|
|
95
|
+
rawEnvironmentConfigs
|
|
96
|
+
} = getRsbuildInspectConfig({
|
|
97
|
+
normalizedConfig: context.normalizedConfig,
|
|
98
|
+
inspectOptions,
|
|
99
|
+
pluginManager
|
|
100
|
+
});
|
|
99
101
|
let outputPath = inspectOptions.outputPath || context.distPath;
|
|
100
102
|
if (!(0, import_node_path.isAbsolute)(outputPath)) {
|
|
101
103
|
outputPath = (0, import_node_path.join)(context.rootPath, outputPath);
|
|
102
104
|
}
|
|
103
105
|
if (inspectOptions.writeToDisk) {
|
|
104
106
|
await outputInspectConfigFiles({
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
bundlerConfigs: rawBundlerConfigs,
|
|
107
|
+
rawBundlerConfigs,
|
|
108
|
+
rawEnvironmentConfigs,
|
|
108
109
|
inspectOptions: {
|
|
109
110
|
...inspectOptions,
|
|
110
111
|
outputPath
|
|
@@ -114,19 +115,20 @@ async function inspectConfig({
|
|
|
114
115
|
}
|
|
115
116
|
return {
|
|
116
117
|
rsbuildConfig: rawRsbuildConfig,
|
|
117
|
-
|
|
118
|
+
environmentConfigs: rawEnvironmentConfigs.map((r) => r.content),
|
|
119
|
+
bundlerConfigs: rawBundlerConfigs.map((r) => r.content),
|
|
118
120
|
origin: {
|
|
119
|
-
rsbuildConfig
|
|
121
|
+
rsbuildConfig,
|
|
122
|
+
environmentConfigs,
|
|
120
123
|
bundlerConfigs: webpackConfigs
|
|
121
124
|
}
|
|
122
125
|
};
|
|
123
126
|
}
|
|
124
|
-
var import_node_path
|
|
127
|
+
var import_node_path;
|
|
125
128
|
var init_inspectConfig = __esm({
|
|
126
129
|
"src/inspectConfig.ts"() {
|
|
127
130
|
"use strict";
|
|
128
131
|
import_node_path = require("path");
|
|
129
|
-
import_shared = require("@rsbuild/shared");
|
|
130
132
|
init_initConfigs();
|
|
131
133
|
init_shared();
|
|
132
134
|
}
|
|
@@ -140,7 +142,7 @@ async function modifyWebpackChain(context, utils, chain) {
|
|
|
140
142
|
utils
|
|
141
143
|
);
|
|
142
144
|
if (context.config.tools?.webpackChain) {
|
|
143
|
-
for (const item of (0,
|
|
145
|
+
for (const item of (0, import_shared2.castArray)(context.config.tools.webpackChain)) {
|
|
144
146
|
item(modifiedChain, utils);
|
|
145
147
|
}
|
|
146
148
|
}
|
|
@@ -154,7 +156,7 @@ async function modifyWebpackConfig(context, webpackConfig, utils) {
|
|
|
154
156
|
utils
|
|
155
157
|
);
|
|
156
158
|
if (context.config.tools?.webpack) {
|
|
157
|
-
modifiedConfig = (0,
|
|
159
|
+
modifiedConfig = (0, import_reduce_configs.reduceConfigsWithContext)({
|
|
158
160
|
initial: modifiedConfig,
|
|
159
161
|
config: context.config.tools.webpack,
|
|
160
162
|
ctx: utils,
|
|
@@ -164,16 +166,15 @@ async function modifyWebpackConfig(context, webpackConfig, utils) {
|
|
|
164
166
|
import_core2.logger.debug("modify webpack config done");
|
|
165
167
|
return modifiedConfig;
|
|
166
168
|
}
|
|
167
|
-
async function getChainUtils2(target) {
|
|
169
|
+
async function getChainUtils2(target, environment) {
|
|
168
170
|
const { default: webpack2 } = await import("webpack");
|
|
169
171
|
const nameMap = {
|
|
170
172
|
web: "client",
|
|
171
173
|
node: "server",
|
|
172
|
-
"web-worker": "web-worker"
|
|
173
|
-
"service-worker": "service-worker"
|
|
174
|
+
"web-worker": "web-worker"
|
|
174
175
|
};
|
|
175
176
|
return {
|
|
176
|
-
...getChainUtils(target),
|
|
177
|
+
...getChainUtils(target, environment),
|
|
177
178
|
name: nameMap[target] || "",
|
|
178
179
|
webpack: webpack2,
|
|
179
180
|
HtmlWebpackPlugin: import_core2.__internalHelper.getHTMLPlugin()
|
|
@@ -185,7 +186,7 @@ async function getConfigUtils(config, chainUtils) {
|
|
|
185
186
|
...chainUtils,
|
|
186
187
|
mergeConfig: merge,
|
|
187
188
|
addRules(rules) {
|
|
188
|
-
const ruleArr = (0,
|
|
189
|
+
const ruleArr = (0, import_shared2.castArray)(rules);
|
|
189
190
|
if (!config.module) {
|
|
190
191
|
config.module = {};
|
|
191
192
|
}
|
|
@@ -195,14 +196,14 @@ async function getConfigUtils(config, chainUtils) {
|
|
|
195
196
|
config.module.rules.unshift(...ruleArr);
|
|
196
197
|
},
|
|
197
198
|
prependPlugins(plugins) {
|
|
198
|
-
const pluginArr = (0,
|
|
199
|
+
const pluginArr = (0, import_shared2.castArray)(plugins);
|
|
199
200
|
if (!config.plugins) {
|
|
200
201
|
config.plugins = [];
|
|
201
202
|
}
|
|
202
203
|
config.plugins.unshift(...pluginArr);
|
|
203
204
|
},
|
|
204
205
|
appendPlugins(plugins) {
|
|
205
|
-
const pluginArr = (0,
|
|
206
|
+
const pluginArr = (0, import_shared2.castArray)(plugins);
|
|
206
207
|
if (!config.plugins) {
|
|
207
208
|
config.plugins = [];
|
|
208
209
|
}
|
|
@@ -219,9 +220,13 @@ async function getConfigUtils(config, chainUtils) {
|
|
|
219
220
|
}
|
|
220
221
|
async function generateWebpackConfig({
|
|
221
222
|
target,
|
|
222
|
-
context
|
|
223
|
+
context,
|
|
224
|
+
environment
|
|
223
225
|
}) {
|
|
224
|
-
const chainUtils = await getChainUtils2(
|
|
226
|
+
const chainUtils = await getChainUtils2(
|
|
227
|
+
target,
|
|
228
|
+
context.environments[environment]
|
|
229
|
+
);
|
|
225
230
|
const { default: webpack2 } = await import("webpack");
|
|
226
231
|
const {
|
|
227
232
|
BannerPlugin,
|
|
@@ -249,12 +254,13 @@ async function generateWebpackConfig({
|
|
|
249
254
|
);
|
|
250
255
|
return webpackConfig;
|
|
251
256
|
}
|
|
252
|
-
var import_core2,
|
|
257
|
+
var import_core2, import_shared2, import_reduce_configs;
|
|
253
258
|
var init_webpackConfig = __esm({
|
|
254
259
|
"src/webpackConfig.ts"() {
|
|
255
260
|
"use strict";
|
|
256
261
|
import_core2 = require("@rsbuild/core");
|
|
257
|
-
|
|
262
|
+
import_shared2 = require("@rsbuild/shared");
|
|
263
|
+
import_reduce_configs = require("reduce-configs");
|
|
258
264
|
init_shared();
|
|
259
265
|
}
|
|
260
266
|
});
|
|
@@ -269,9 +275,14 @@ async function initConfigs({
|
|
|
269
275
|
context,
|
|
270
276
|
pluginManager
|
|
271
277
|
});
|
|
272
|
-
const { targets } = normalizedConfig.output;
|
|
273
278
|
const webpackConfigs = await Promise.all(
|
|
274
|
-
|
|
279
|
+
Object.entries(normalizedConfig.environments).map(
|
|
280
|
+
([environment, config]) => generateWebpackConfig({
|
|
281
|
+
target: config.output.target,
|
|
282
|
+
context,
|
|
283
|
+
environment
|
|
284
|
+
})
|
|
285
|
+
)
|
|
275
286
|
);
|
|
276
287
|
if (import_core3.logger.level === "verbose") {
|
|
277
288
|
const inspect = () => {
|
|
@@ -317,7 +328,8 @@ async function createCompiler({
|
|
|
317
328
|
}) {
|
|
318
329
|
import_core4.logger.debug("create compiler");
|
|
319
330
|
await context.hooks.onBeforeCreateCompiler.call({
|
|
320
|
-
bundlerConfigs: webpackConfigs
|
|
331
|
+
bundlerConfigs: webpackConfigs,
|
|
332
|
+
environments: context.environments
|
|
321
333
|
});
|
|
322
334
|
const { default: webpack2 } = await import("webpack");
|
|
323
335
|
const compiler = webpackConfigs.length === 1 ? webpack2(webpackConfigs[0]) : webpack2(webpackConfigs);
|
|
@@ -332,10 +344,11 @@ async function createCompiler({
|
|
|
332
344
|
if (level === "warning") {
|
|
333
345
|
import_core4.logger.warn(message);
|
|
334
346
|
}
|
|
335
|
-
if (
|
|
347
|
+
if (process.env.NODE_ENV === "development") {
|
|
336
348
|
await context.hooks.onDevCompileDone.call({
|
|
337
349
|
isFirstCompile,
|
|
338
|
-
stats
|
|
350
|
+
stats,
|
|
351
|
+
environments: context.environments
|
|
339
352
|
});
|
|
340
353
|
}
|
|
341
354
|
isFirstCompile = false;
|
|
@@ -343,7 +356,8 @@ async function createCompiler({
|
|
|
343
356
|
let isFirstCompile = true;
|
|
344
357
|
onCompileDone(compiler, done, import_MultiStats.default);
|
|
345
358
|
await context.hooks.onAfterCreateCompiler.call({
|
|
346
|
-
compiler
|
|
359
|
+
compiler,
|
|
360
|
+
environments: context.environments
|
|
347
361
|
});
|
|
348
362
|
import_core4.logger.debug("create compiler done");
|
|
349
363
|
return compiler;
|
|
@@ -364,12 +378,11 @@ async function createDevMiddleware(options, customCompiler) {
|
|
|
364
378
|
compiler
|
|
365
379
|
};
|
|
366
380
|
}
|
|
367
|
-
var import_core4,
|
|
381
|
+
var import_core4, import_MultiStats;
|
|
368
382
|
var init_createCompiler = __esm({
|
|
369
383
|
"src/createCompiler.ts"() {
|
|
370
384
|
"use strict";
|
|
371
385
|
import_core4 = require("@rsbuild/core");
|
|
372
|
-
import_shared6 = require("@rsbuild/shared");
|
|
373
386
|
import_MultiStats = __toESM(require("webpack/lib/MultiStats.js"));
|
|
374
387
|
init_initConfigs();
|
|
375
388
|
init_shared();
|
|
@@ -1030,18 +1043,18 @@ var require_conversions = __commonJS({
|
|
|
1030
1043
|
return ansi;
|
|
1031
1044
|
};
|
|
1032
1045
|
convert.ansi16.rgb = function(args) {
|
|
1033
|
-
let
|
|
1034
|
-
if (
|
|
1046
|
+
let color3 = args % 10;
|
|
1047
|
+
if (color3 === 0 || color3 === 7) {
|
|
1035
1048
|
if (args > 50) {
|
|
1036
|
-
|
|
1049
|
+
color3 += 3.5;
|
|
1037
1050
|
}
|
|
1038
|
-
|
|
1039
|
-
return [
|
|
1051
|
+
color3 = color3 / 10.5 * 255;
|
|
1052
|
+
return [color3, color3, color3];
|
|
1040
1053
|
}
|
|
1041
1054
|
const mult = (~~(args > 50) + 1) * 0.5;
|
|
1042
|
-
const r = (
|
|
1043
|
-
const g = (
|
|
1044
|
-
const b = (
|
|
1055
|
+
const r = (color3 & 1) * mult * 255;
|
|
1056
|
+
const g = (color3 >> 1 & 1) * mult * 255;
|
|
1057
|
+
const b = (color3 >> 2 & 1) * mult * 255;
|
|
1045
1058
|
return [r, g, b];
|
|
1046
1059
|
};
|
|
1047
1060
|
convert.ansi256.rgb = function(args) {
|
|
@@ -1826,11 +1839,11 @@ var init_utils = __esm({
|
|
|
1826
1839
|
});
|
|
1827
1840
|
|
|
1828
1841
|
// src/progress/helpers/bar.ts
|
|
1829
|
-
var
|
|
1842
|
+
var import_shared7, import_cli_truncate, defaultOption, padding, FULL_WIDTH, MIDDLE_WIDTH, renderBar;
|
|
1830
1843
|
var init_bar = __esm({
|
|
1831
1844
|
"src/progress/helpers/bar.ts"() {
|
|
1832
1845
|
"use strict";
|
|
1833
|
-
|
|
1846
|
+
import_shared7 = require("@rsbuild/shared");
|
|
1834
1847
|
import_cli_truncate = __toESM(require_cli_truncate());
|
|
1835
1848
|
init_utils();
|
|
1836
1849
|
defaultOption = {
|
|
@@ -1872,7 +1885,7 @@ var init_bar = __esm({
|
|
|
1872
1885
|
errorInfo,
|
|
1873
1886
|
width,
|
|
1874
1887
|
current,
|
|
1875
|
-
color,
|
|
1888
|
+
color: color3,
|
|
1876
1889
|
bgColor,
|
|
1877
1890
|
char,
|
|
1878
1891
|
message,
|
|
@@ -1884,15 +1897,15 @@ var init_bar = __esm({
|
|
|
1884
1897
|
} = mergedOptions;
|
|
1885
1898
|
const space = " ".repeat(spaceWidth);
|
|
1886
1899
|
const percent = clamp(Math.floor(current / total * 100), 0, 100);
|
|
1887
|
-
const barColor =
|
|
1888
|
-
const backgroundColor =
|
|
1889
|
-
const doneColor = hasErrors ?
|
|
1900
|
+
const barColor = import_shared7.color[color3];
|
|
1901
|
+
const backgroundColor = import_shared7.color[bgColor];
|
|
1902
|
+
const doneColor = hasErrors ? import_shared7.color.red : barColor;
|
|
1890
1903
|
const idColor = done ? doneColor : barColor;
|
|
1891
1904
|
const id = mergedOptions.id ? idColor(padding(mergedOptions.id, maxIdLen)) : "";
|
|
1892
1905
|
const { columns: terminalWidth = FULL_WIDTH } = process.stdout;
|
|
1893
1906
|
if (done) {
|
|
1894
1907
|
if (hasErrors) {
|
|
1895
|
-
const message2 =
|
|
1908
|
+
const message2 = import_shared7.color.bold(doneColor(errorInfo));
|
|
1896
1909
|
if (terminalWidth >= MIDDLE_WIDTH) {
|
|
1897
1910
|
return [idColor(errorIcon), id, doneColor(`${space}${message2}`)].join(
|
|
1898
1911
|
""
|
|
@@ -1902,7 +1915,7 @@ var init_bar = __esm({
|
|
|
1902
1915
|
}
|
|
1903
1916
|
return "";
|
|
1904
1917
|
}
|
|
1905
|
-
const msgStr =
|
|
1918
|
+
const msgStr = import_shared7.color[messageColor](
|
|
1906
1919
|
(0, import_cli_truncate.default)(message, messageWidth, { position: "start" })
|
|
1907
1920
|
);
|
|
1908
1921
|
const left = clamp(Math.floor(percent * width / 100), 0, width);
|
|
@@ -2228,30 +2241,32 @@ function createNonTTYLogger() {
|
|
|
2228
2241
|
hasErrors,
|
|
2229
2242
|
compileTime
|
|
2230
2243
|
}) => {
|
|
2244
|
+
const suffix = import_shared8.color.gray(`(${id})`);
|
|
2231
2245
|
if (done) {
|
|
2232
2246
|
if (prevPercentage === 100) {
|
|
2233
2247
|
return;
|
|
2234
2248
|
}
|
|
2235
2249
|
prevPercentage = 100;
|
|
2236
2250
|
if (hasErrors) {
|
|
2237
|
-
import_core5.logger.error(
|
|
2251
|
+
import_core5.logger.error(`Compile failed in ${compileTime} ${suffix}`);
|
|
2238
2252
|
} else {
|
|
2239
|
-
import_core5.logger.ready(
|
|
2253
|
+
import_core5.logger.ready(`Compiled in ${compileTime} ${suffix}`);
|
|
2240
2254
|
}
|
|
2241
2255
|
} else if (current - prevPercentage > 10) {
|
|
2242
2256
|
prevPercentage = current;
|
|
2243
|
-
import_core5.logger.info(
|
|
2257
|
+
import_core5.logger.info(`Compile progress: ${current.toFixed(0)}% ${suffix}`);
|
|
2244
2258
|
}
|
|
2245
2259
|
};
|
|
2246
2260
|
return {
|
|
2247
2261
|
log
|
|
2248
2262
|
};
|
|
2249
2263
|
}
|
|
2250
|
-
var import_core5;
|
|
2264
|
+
var import_core5, import_shared8;
|
|
2251
2265
|
var init_nonTty = __esm({
|
|
2252
2266
|
"src/progress/helpers/nonTty.ts"() {
|
|
2253
2267
|
"use strict";
|
|
2254
2268
|
import_core5 = require("@rsbuild/core");
|
|
2269
|
+
import_shared8 = require("@rsbuild/shared");
|
|
2255
2270
|
}
|
|
2256
2271
|
});
|
|
2257
2272
|
|
|
@@ -2260,13 +2275,14 @@ var ProgressPlugin_exports = {};
|
|
|
2260
2275
|
__export(ProgressPlugin_exports, {
|
|
2261
2276
|
ProgressPlugin: () => ProgressPlugin
|
|
2262
2277
|
});
|
|
2263
|
-
var import_core6,
|
|
2278
|
+
var import_core6, import_shared9, import_webpack, ProgressPlugin;
|
|
2264
2279
|
var init_ProgressPlugin = __esm({
|
|
2265
2280
|
"src/progress/ProgressPlugin.ts"() {
|
|
2266
2281
|
"use strict";
|
|
2267
2282
|
import_core6 = require("@rsbuild/core");
|
|
2268
|
-
|
|
2283
|
+
import_shared9 = require("@rsbuild/shared");
|
|
2269
2284
|
import_webpack = __toESM(require("webpack"));
|
|
2285
|
+
init_shared();
|
|
2270
2286
|
init_helpers();
|
|
2271
2287
|
init_nonTty();
|
|
2272
2288
|
ProgressPlugin = class extends import_webpack.default.ProgressPlugin {
|
|
@@ -2324,10 +2340,11 @@ var init_ProgressPlugin = __esm({
|
|
|
2324
2340
|
this.hasCompileErrors = stat.hasErrors();
|
|
2325
2341
|
const hrtime = process.hrtime(startTime);
|
|
2326
2342
|
const seconds = hrtime[0] + hrtime[1] / 1e9;
|
|
2327
|
-
this.compileTime =
|
|
2343
|
+
this.compileTime = prettyTime(seconds);
|
|
2328
2344
|
startTime = null;
|
|
2329
2345
|
if (!this.hasCompileErrors) {
|
|
2330
|
-
|
|
2346
|
+
const suffix = this.id ? import_shared9.color.gray(` (${this.id})`) : "";
|
|
2347
|
+
import_core6.logger.ready(`Compiled in ${this.compileTime} ${suffix}`);
|
|
2331
2348
|
}
|
|
2332
2349
|
}
|
|
2333
2350
|
});
|
|
@@ -2368,7 +2385,6 @@ var init_plugin = __esm({
|
|
|
2368
2385
|
"use strict";
|
|
2369
2386
|
import_node_fs = __toESM(require("fs"));
|
|
2370
2387
|
import_shared11 = require("@rsbuild/shared");
|
|
2371
|
-
init_shared();
|
|
2372
2388
|
getMainFields = (chain, target) => {
|
|
2373
2389
|
const mainFields = chain.resolve.mainFields.values();
|
|
2374
2390
|
if (mainFields.length) {
|
|
@@ -2382,13 +2398,13 @@ var init_plugin = __esm({
|
|
|
2382
2398
|
pluginAdaptor = () => ({
|
|
2383
2399
|
name: "rsbuild-webpack:adaptor",
|
|
2384
2400
|
setup(api) {
|
|
2385
|
-
api.modifyBundlerChain(async (chain, { CHAIN_ID, target }) => {
|
|
2386
|
-
const config =
|
|
2387
|
-
if (
|
|
2401
|
+
api.modifyBundlerChain(async (chain, { CHAIN_ID, environment, target }) => {
|
|
2402
|
+
const { config, tsconfigPath } = environment;
|
|
2403
|
+
if (tsconfigPath && config.source.aliasStrategy === "prefer-tsconfig") {
|
|
2388
2404
|
await applyTsConfigPathsPlugin({
|
|
2389
2405
|
chain,
|
|
2390
2406
|
CHAIN_ID,
|
|
2391
|
-
configFile:
|
|
2407
|
+
configFile: tsconfigPath,
|
|
2392
2408
|
mainFields: getMainFields(chain, target),
|
|
2393
2409
|
extensions: chain.resolve.extensions.values()
|
|
2394
2410
|
});
|
|
@@ -2398,19 +2414,19 @@ var init_plugin = __esm({
|
|
|
2398
2414
|
const { ProgressPlugin: ProgressPlugin2 } = await Promise.resolve().then(() => (init_ProgressPlugin(), ProgressPlugin_exports));
|
|
2399
2415
|
chain.plugin(CHAIN_ID.PLUGIN.PROGRESS).use(ProgressPlugin2, [
|
|
2400
2416
|
{
|
|
2401
|
-
id:
|
|
2417
|
+
id: environment.name,
|
|
2402
2418
|
...progress === true ? {} : progress
|
|
2403
2419
|
}
|
|
2404
2420
|
]);
|
|
2405
2421
|
}
|
|
2406
2422
|
const { copy } = config.output;
|
|
2407
2423
|
if (copy) {
|
|
2408
|
-
const { default: CopyPlugin } = await import(
|
|
2409
|
-
// @ts-expect-error copy-webpack-plugin does not provide types
|
|
2410
|
-
"copy-webpack-plugin"
|
|
2411
|
-
);
|
|
2424
|
+
const { default: CopyPlugin } = await import("copy-webpack-plugin");
|
|
2412
2425
|
const options = Array.isArray(copy) ? { patterns: copy } : copy;
|
|
2413
|
-
chain.plugin(CHAIN_ID.PLUGIN.COPY).use(CopyPlugin, [
|
|
2426
|
+
chain.plugin(CHAIN_ID.PLUGIN.COPY).use(CopyPlugin, [
|
|
2427
|
+
// @ts-expect-error to type mismatch
|
|
2428
|
+
options
|
|
2429
|
+
]);
|
|
2414
2430
|
}
|
|
2415
2431
|
});
|
|
2416
2432
|
api.modifyWebpackConfig(async (config) => {
|
|
@@ -2438,19 +2454,18 @@ var build_exports = {};
|
|
|
2438
2454
|
__export(build_exports, {
|
|
2439
2455
|
build: () => build
|
|
2440
2456
|
});
|
|
2441
|
-
var import_core7,
|
|
2457
|
+
var import_core7, import_MultiStats2, build;
|
|
2442
2458
|
var init_build = __esm({
|
|
2443
2459
|
"src/build.ts"() {
|
|
2444
2460
|
"use strict";
|
|
2445
2461
|
import_core7 = require("@rsbuild/core");
|
|
2446
|
-
import_shared13 = require("@rsbuild/shared");
|
|
2447
2462
|
import_MultiStats2 = __toESM(require("webpack/lib/MultiStats.js"));
|
|
2448
2463
|
init_createCompiler();
|
|
2449
2464
|
init_initConfigs();
|
|
2450
2465
|
init_shared();
|
|
2451
2466
|
build = async (initOptions, { mode = "production", watch, compiler: customCompiler } = {}) => {
|
|
2452
|
-
if (!
|
|
2453
|
-
|
|
2467
|
+
if (!process.env.NODE_ENV) {
|
|
2468
|
+
process.env.NODE_ENV = mode;
|
|
2454
2469
|
}
|
|
2455
2470
|
const { context } = initOptions;
|
|
2456
2471
|
let compiler;
|
|
@@ -2467,10 +2482,15 @@ var init_build = __esm({
|
|
|
2467
2482
|
}
|
|
2468
2483
|
let isFirstCompile = true;
|
|
2469
2484
|
await context.hooks.onBeforeBuild.call({
|
|
2470
|
-
bundlerConfigs
|
|
2485
|
+
bundlerConfigs,
|
|
2486
|
+
environments: context.environments
|
|
2471
2487
|
});
|
|
2472
2488
|
const onDone = async (stats) => {
|
|
2473
|
-
const p = context.hooks.onAfterBuild.call({
|
|
2489
|
+
const p = context.hooks.onAfterBuild.call({
|
|
2490
|
+
isFirstCompile,
|
|
2491
|
+
stats,
|
|
2492
|
+
environments: context.environments
|
|
2493
|
+
});
|
|
2474
2494
|
isFirstCompile = false;
|
|
2475
2495
|
await p;
|
|
2476
2496
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
3
|
-
|
|
4
|
-
declare const webpackProvider: RsbuildProvider<'webpack'>;
|
|
5
|
-
|
|
6
|
-
export { webpackProvider };
|
|
1
|
+
export { webpackProvider } from './provider';
|
|
2
|
+
export type { webpack, WebpackConfig, } from './types';
|
package/dist/index.js
CHANGED
|
@@ -46,18 +46,18 @@ var __publicField = (obj, key, value) => {
|
|
|
46
46
|
return value;
|
|
47
47
|
};
|
|
48
48
|
|
|
49
|
-
// ../../../node_modules/.pnpm/@modern-js+module-tools@2.
|
|
49
|
+
// ../../../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
|
|
50
50
|
import { fileURLToPath } from "url";
|
|
51
51
|
import path from "path";
|
|
52
52
|
var init_esm = __esm({
|
|
53
|
-
"../../../node_modules/.pnpm/@modern-js+module-tools@2.
|
|
53
|
+
"../../../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"() {
|
|
54
54
|
"use strict";
|
|
55
55
|
}
|
|
56
56
|
});
|
|
57
57
|
|
|
58
58
|
// src/shared.ts
|
|
59
59
|
import { __internalHelper } from "@rsbuild/core";
|
|
60
|
-
var getChainUtils, initRsbuildConfig, createDevServer, formatStats, getDevMiddleware, getStatsOptions, stringifyConfig, outputInspectConfigFiles, chainToConfig, modifyBundlerChain, onCompileDone,
|
|
60
|
+
var getChainUtils, initRsbuildConfig, createDevServer, formatStats, getDevMiddleware, getStatsOptions, stringifyConfig, outputInspectConfigFiles, getRsbuildInspectConfig, chainToConfig, modifyBundlerChain, onCompileDone, prettyTime;
|
|
61
61
|
var init_shared = __esm({
|
|
62
62
|
"src/shared.ts"() {
|
|
63
63
|
"use strict";
|
|
@@ -71,10 +71,11 @@ var init_shared = __esm({
|
|
|
71
71
|
getStatsOptions,
|
|
72
72
|
stringifyConfig,
|
|
73
73
|
outputInspectConfigFiles,
|
|
74
|
+
getRsbuildInspectConfig,
|
|
74
75
|
chainToConfig,
|
|
75
76
|
modifyBundlerChain,
|
|
76
77
|
onCompileDone,
|
|
77
|
-
|
|
78
|
+
prettyTime
|
|
78
79
|
} = __internalHelper);
|
|
79
80
|
}
|
|
80
81
|
});
|
|
@@ -85,7 +86,6 @@ __export(inspectConfig_exports, {
|
|
|
85
86
|
inspectConfig: () => inspectConfig
|
|
86
87
|
});
|
|
87
88
|
import { isAbsolute, join } from "path";
|
|
88
|
-
import { getNodeEnv, setNodeEnv } from "@rsbuild/shared";
|
|
89
89
|
async function inspectConfig({
|
|
90
90
|
context,
|
|
91
91
|
pluginManager,
|
|
@@ -94,37 +94,37 @@ async function inspectConfig({
|
|
|
94
94
|
inspectOptions = {}
|
|
95
95
|
}) {
|
|
96
96
|
if (inspectOptions.env) {
|
|
97
|
-
|
|
98
|
-
} else if (!
|
|
99
|
-
|
|
97
|
+
process.env.NODE_ENV = inspectOptions.env;
|
|
98
|
+
} else if (!process.env.NODE_ENV) {
|
|
99
|
+
process.env.NODE_ENV = "development";
|
|
100
100
|
}
|
|
101
101
|
const webpackConfigs = bundlerConfigs || (await initConfigs({
|
|
102
102
|
context,
|
|
103
103
|
pluginManager,
|
|
104
104
|
rsbuildOptions
|
|
105
105
|
})).webpackConfigs;
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
};
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
106
|
+
const rawBundlerConfigs = webpackConfigs.map((config, index) => ({
|
|
107
|
+
name: config.name || String(index),
|
|
108
|
+
content: stringifyConfig(config, inspectOptions.verbose)
|
|
109
|
+
}));
|
|
110
|
+
const {
|
|
111
|
+
rsbuildConfig,
|
|
112
|
+
rawRsbuildConfig,
|
|
113
|
+
environmentConfigs,
|
|
114
|
+
rawEnvironmentConfigs
|
|
115
|
+
} = getRsbuildInspectConfig({
|
|
116
|
+
normalizedConfig: context.normalizedConfig,
|
|
117
|
+
inspectOptions,
|
|
118
|
+
pluginManager
|
|
119
|
+
});
|
|
119
120
|
let outputPath = inspectOptions.outputPath || context.distPath;
|
|
120
121
|
if (!isAbsolute(outputPath)) {
|
|
121
122
|
outputPath = join(context.rootPath, outputPath);
|
|
122
123
|
}
|
|
123
124
|
if (inspectOptions.writeToDisk) {
|
|
124
125
|
await outputInspectConfigFiles({
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
bundlerConfigs: rawBundlerConfigs,
|
|
126
|
+
rawBundlerConfigs,
|
|
127
|
+
rawEnvironmentConfigs,
|
|
128
128
|
inspectOptions: {
|
|
129
129
|
...inspectOptions,
|
|
130
130
|
outputPath
|
|
@@ -134,9 +134,11 @@ async function inspectConfig({
|
|
|
134
134
|
}
|
|
135
135
|
return {
|
|
136
136
|
rsbuildConfig: rawRsbuildConfig,
|
|
137
|
-
|
|
137
|
+
environmentConfigs: rawEnvironmentConfigs.map((r) => r.content),
|
|
138
|
+
bundlerConfigs: rawBundlerConfigs.map((r) => r.content),
|
|
138
139
|
origin: {
|
|
139
|
-
rsbuildConfig
|
|
140
|
+
rsbuildConfig,
|
|
141
|
+
environmentConfigs,
|
|
140
142
|
bundlerConfigs: webpackConfigs
|
|
141
143
|
}
|
|
142
144
|
};
|
|
@@ -156,9 +158,9 @@ import {
|
|
|
156
158
|
logger
|
|
157
159
|
} from "@rsbuild/core";
|
|
158
160
|
import {
|
|
159
|
-
castArray
|
|
160
|
-
reduceConfigsWithContext
|
|
161
|
+
castArray
|
|
161
162
|
} from "@rsbuild/shared";
|
|
163
|
+
import { reduceConfigsWithContext } from "reduce-configs";
|
|
162
164
|
async function modifyWebpackChain(context, utils, chain) {
|
|
163
165
|
logger.debug("modify webpack chain");
|
|
164
166
|
const [modifiedChain] = await context.hooks.modifyWebpackChain.call(
|
|
@@ -190,16 +192,15 @@ async function modifyWebpackConfig(context, webpackConfig, utils) {
|
|
|
190
192
|
logger.debug("modify webpack config done");
|
|
191
193
|
return modifiedConfig;
|
|
192
194
|
}
|
|
193
|
-
async function getChainUtils2(target) {
|
|
195
|
+
async function getChainUtils2(target, environment) {
|
|
194
196
|
const { default: webpack2 } = await import("webpack");
|
|
195
197
|
const nameMap = {
|
|
196
198
|
web: "client",
|
|
197
199
|
node: "server",
|
|
198
|
-
"web-worker": "web-worker"
|
|
199
|
-
"service-worker": "service-worker"
|
|
200
|
+
"web-worker": "web-worker"
|
|
200
201
|
};
|
|
201
202
|
return {
|
|
202
|
-
...getChainUtils(target),
|
|
203
|
+
...getChainUtils(target, environment),
|
|
203
204
|
name: nameMap[target] || "",
|
|
204
205
|
webpack: webpack2,
|
|
205
206
|
HtmlWebpackPlugin: __internalHelper2.getHTMLPlugin()
|
|
@@ -245,9 +246,13 @@ async function getConfigUtils(config, chainUtils) {
|
|
|
245
246
|
}
|
|
246
247
|
async function generateWebpackConfig({
|
|
247
248
|
target,
|
|
248
|
-
context
|
|
249
|
+
context,
|
|
250
|
+
environment
|
|
249
251
|
}) {
|
|
250
|
-
const chainUtils = await getChainUtils2(
|
|
252
|
+
const chainUtils = await getChainUtils2(
|
|
253
|
+
target,
|
|
254
|
+
context.environments[environment]
|
|
255
|
+
);
|
|
251
256
|
const { default: webpack2 } = await import("webpack");
|
|
252
257
|
const {
|
|
253
258
|
BannerPlugin,
|
|
@@ -296,9 +301,14 @@ async function initConfigs({
|
|
|
296
301
|
context,
|
|
297
302
|
pluginManager
|
|
298
303
|
});
|
|
299
|
-
const { targets } = normalizedConfig.output;
|
|
300
304
|
const webpackConfigs = await Promise.all(
|
|
301
|
-
|
|
305
|
+
Object.entries(normalizedConfig.environments).map(
|
|
306
|
+
([environment, config]) => generateWebpackConfig({
|
|
307
|
+
target: config.output.target,
|
|
308
|
+
context,
|
|
309
|
+
environment
|
|
310
|
+
})
|
|
311
|
+
)
|
|
302
312
|
);
|
|
303
313
|
if (logger2.level === "verbose") {
|
|
304
314
|
const inspect = () => {
|
|
@@ -338,7 +348,6 @@ __export(createCompiler_exports, {
|
|
|
338
348
|
createDevMiddleware: () => createDevMiddleware
|
|
339
349
|
});
|
|
340
350
|
import { logger as logger3 } from "@rsbuild/core";
|
|
341
|
-
import { isDev } from "@rsbuild/shared";
|
|
342
351
|
import WebpackMultiStats from "webpack/lib/MultiStats.js";
|
|
343
352
|
async function createCompiler({
|
|
344
353
|
context,
|
|
@@ -346,7 +355,8 @@ async function createCompiler({
|
|
|
346
355
|
}) {
|
|
347
356
|
logger3.debug("create compiler");
|
|
348
357
|
await context.hooks.onBeforeCreateCompiler.call({
|
|
349
|
-
bundlerConfigs: webpackConfigs
|
|
358
|
+
bundlerConfigs: webpackConfigs,
|
|
359
|
+
environments: context.environments
|
|
350
360
|
});
|
|
351
361
|
const { default: webpack2 } = await import("webpack");
|
|
352
362
|
const compiler = webpackConfigs.length === 1 ? webpack2(webpackConfigs[0]) : webpack2(webpackConfigs);
|
|
@@ -361,10 +371,11 @@ async function createCompiler({
|
|
|
361
371
|
if (level === "warning") {
|
|
362
372
|
logger3.warn(message);
|
|
363
373
|
}
|
|
364
|
-
if (
|
|
374
|
+
if (process.env.NODE_ENV === "development") {
|
|
365
375
|
await context.hooks.onDevCompileDone.call({
|
|
366
376
|
isFirstCompile,
|
|
367
|
-
stats
|
|
377
|
+
stats,
|
|
378
|
+
environments: context.environments
|
|
368
379
|
});
|
|
369
380
|
}
|
|
370
381
|
isFirstCompile = false;
|
|
@@ -372,7 +383,8 @@ async function createCompiler({
|
|
|
372
383
|
let isFirstCompile = true;
|
|
373
384
|
onCompileDone(compiler, done, WebpackMultiStats);
|
|
374
385
|
await context.hooks.onAfterCreateCompiler.call({
|
|
375
|
-
compiler
|
|
386
|
+
compiler,
|
|
387
|
+
environments: context.environments
|
|
376
388
|
});
|
|
377
389
|
logger3.debug("create compiler done");
|
|
378
390
|
return compiler;
|
|
@@ -1060,18 +1072,18 @@ var require_conversions = __commonJS({
|
|
|
1060
1072
|
return ansi;
|
|
1061
1073
|
};
|
|
1062
1074
|
convert.ansi16.rgb = function(args) {
|
|
1063
|
-
let
|
|
1064
|
-
if (
|
|
1075
|
+
let color3 = args % 10;
|
|
1076
|
+
if (color3 === 0 || color3 === 7) {
|
|
1065
1077
|
if (args > 50) {
|
|
1066
|
-
|
|
1078
|
+
color3 += 3.5;
|
|
1067
1079
|
}
|
|
1068
|
-
|
|
1069
|
-
return [
|
|
1080
|
+
color3 = color3 / 10.5 * 255;
|
|
1081
|
+
return [color3, color3, color3];
|
|
1070
1082
|
}
|
|
1071
1083
|
const mult = (~~(args > 50) + 1) * 0.5;
|
|
1072
|
-
const r = (
|
|
1073
|
-
const g = (
|
|
1074
|
-
const b = (
|
|
1084
|
+
const r = (color3 & 1) * mult * 255;
|
|
1085
|
+
const g = (color3 >> 1 & 1) * mult * 255;
|
|
1086
|
+
const b = (color3 >> 2 & 1) * mult * 255;
|
|
1075
1087
|
return [r, g, b];
|
|
1076
1088
|
};
|
|
1077
1089
|
convert.ansi256.rgb = function(args) {
|
|
@@ -1914,7 +1926,7 @@ var init_bar = __esm({
|
|
|
1914
1926
|
errorInfo,
|
|
1915
1927
|
width,
|
|
1916
1928
|
current,
|
|
1917
|
-
color,
|
|
1929
|
+
color: color3,
|
|
1918
1930
|
bgColor,
|
|
1919
1931
|
char,
|
|
1920
1932
|
message,
|
|
@@ -1926,7 +1938,7 @@ var init_bar = __esm({
|
|
|
1926
1938
|
} = mergedOptions;
|
|
1927
1939
|
const space = " ".repeat(spaceWidth);
|
|
1928
1940
|
const percent = clamp(Math.floor(current / total * 100), 0, 100);
|
|
1929
|
-
const barColor = colors[
|
|
1941
|
+
const barColor = colors[color3];
|
|
1930
1942
|
const backgroundColor = colors[bgColor];
|
|
1931
1943
|
const doneColor = hasErrors ? colors.red : barColor;
|
|
1932
1944
|
const idColor = done ? doneColor : barColor;
|
|
@@ -2268,6 +2280,7 @@ var init_helpers = __esm({
|
|
|
2268
2280
|
|
|
2269
2281
|
// src/progress/helpers/nonTty.ts
|
|
2270
2282
|
import { logger as logger4 } from "@rsbuild/core";
|
|
2283
|
+
import { color } from "@rsbuild/shared";
|
|
2271
2284
|
function createNonTTYLogger() {
|
|
2272
2285
|
let prevPercentage = 0;
|
|
2273
2286
|
const log = ({
|
|
@@ -2277,19 +2290,20 @@ function createNonTTYLogger() {
|
|
|
2277
2290
|
hasErrors,
|
|
2278
2291
|
compileTime
|
|
2279
2292
|
}) => {
|
|
2293
|
+
const suffix = color.gray(`(${id})`);
|
|
2280
2294
|
if (done) {
|
|
2281
2295
|
if (prevPercentage === 100) {
|
|
2282
2296
|
return;
|
|
2283
2297
|
}
|
|
2284
2298
|
prevPercentage = 100;
|
|
2285
2299
|
if (hasErrors) {
|
|
2286
|
-
logger4.error(
|
|
2300
|
+
logger4.error(`Compile failed in ${compileTime} ${suffix}`);
|
|
2287
2301
|
} else {
|
|
2288
|
-
logger4.ready(
|
|
2302
|
+
logger4.ready(`Compiled in ${compileTime} ${suffix}`);
|
|
2289
2303
|
}
|
|
2290
2304
|
} else if (current - prevPercentage > 10) {
|
|
2291
2305
|
prevPercentage = current;
|
|
2292
|
-
logger4.info(
|
|
2306
|
+
logger4.info(`Compile progress: ${current.toFixed(0)}% ${suffix}`);
|
|
2293
2307
|
}
|
|
2294
2308
|
};
|
|
2295
2309
|
return {
|
|
@@ -2309,13 +2323,14 @@ __export(ProgressPlugin_exports, {
|
|
|
2309
2323
|
ProgressPlugin: () => ProgressPlugin
|
|
2310
2324
|
});
|
|
2311
2325
|
import { logger as logger5 } from "@rsbuild/core";
|
|
2312
|
-
import {
|
|
2326
|
+
import { color as color2 } from "@rsbuild/shared";
|
|
2313
2327
|
import webpack from "webpack";
|
|
2314
2328
|
var ProgressPlugin;
|
|
2315
2329
|
var init_ProgressPlugin = __esm({
|
|
2316
2330
|
"src/progress/ProgressPlugin.ts"() {
|
|
2317
2331
|
"use strict";
|
|
2318
2332
|
init_esm();
|
|
2333
|
+
init_shared();
|
|
2319
2334
|
init_helpers();
|
|
2320
2335
|
init_nonTty();
|
|
2321
2336
|
ProgressPlugin = class extends webpack.ProgressPlugin {
|
|
@@ -2376,7 +2391,8 @@ var init_ProgressPlugin = __esm({
|
|
|
2376
2391
|
this.compileTime = prettyTime(seconds);
|
|
2377
2392
|
startTime = null;
|
|
2378
2393
|
if (!this.hasCompileErrors) {
|
|
2379
|
-
|
|
2394
|
+
const suffix = this.id ? color2.gray(` (${this.id})`) : "";
|
|
2395
|
+
logger5.ready(`Compiled in ${this.compileTime} ${suffix}`);
|
|
2380
2396
|
}
|
|
2381
2397
|
}
|
|
2382
2398
|
});
|
|
@@ -2418,7 +2434,6 @@ var init_plugin = __esm({
|
|
|
2418
2434
|
"src/plugin.ts"() {
|
|
2419
2435
|
"use strict";
|
|
2420
2436
|
init_esm();
|
|
2421
|
-
init_shared();
|
|
2422
2437
|
getMainFields = (chain, target) => {
|
|
2423
2438
|
const mainFields = chain.resolve.mainFields.values();
|
|
2424
2439
|
if (mainFields.length) {
|
|
@@ -2432,13 +2447,13 @@ var init_plugin = __esm({
|
|
|
2432
2447
|
pluginAdaptor = () => ({
|
|
2433
2448
|
name: "rsbuild-webpack:adaptor",
|
|
2434
2449
|
setup(api) {
|
|
2435
|
-
api.modifyBundlerChain(async (chain, { CHAIN_ID, target }) => {
|
|
2436
|
-
const config =
|
|
2437
|
-
if (
|
|
2450
|
+
api.modifyBundlerChain(async (chain, { CHAIN_ID, environment, target }) => {
|
|
2451
|
+
const { config, tsconfigPath } = environment;
|
|
2452
|
+
if (tsconfigPath && config.source.aliasStrategy === "prefer-tsconfig") {
|
|
2438
2453
|
await applyTsConfigPathsPlugin({
|
|
2439
2454
|
chain,
|
|
2440
2455
|
CHAIN_ID,
|
|
2441
|
-
configFile:
|
|
2456
|
+
configFile: tsconfigPath,
|
|
2442
2457
|
mainFields: getMainFields(chain, target),
|
|
2443
2458
|
extensions: chain.resolve.extensions.values()
|
|
2444
2459
|
});
|
|
@@ -2448,19 +2463,19 @@ var init_plugin = __esm({
|
|
|
2448
2463
|
const { ProgressPlugin: ProgressPlugin2 } = await Promise.resolve().then(() => (init_ProgressPlugin(), ProgressPlugin_exports));
|
|
2449
2464
|
chain.plugin(CHAIN_ID.PLUGIN.PROGRESS).use(ProgressPlugin2, [
|
|
2450
2465
|
{
|
|
2451
|
-
id:
|
|
2466
|
+
id: environment.name,
|
|
2452
2467
|
...progress === true ? {} : progress
|
|
2453
2468
|
}
|
|
2454
2469
|
]);
|
|
2455
2470
|
}
|
|
2456
2471
|
const { copy } = config.output;
|
|
2457
2472
|
if (copy) {
|
|
2458
|
-
const { default: CopyPlugin } = await import(
|
|
2459
|
-
// @ts-expect-error copy-webpack-plugin does not provide types
|
|
2460
|
-
"copy-webpack-plugin"
|
|
2461
|
-
);
|
|
2473
|
+
const { default: CopyPlugin } = await import("copy-webpack-plugin");
|
|
2462
2474
|
const options = Array.isArray(copy) ? { patterns: copy } : copy;
|
|
2463
|
-
chain.plugin(CHAIN_ID.PLUGIN.COPY).use(CopyPlugin, [
|
|
2475
|
+
chain.plugin(CHAIN_ID.PLUGIN.COPY).use(CopyPlugin, [
|
|
2476
|
+
// @ts-expect-error to type mismatch
|
|
2477
|
+
options
|
|
2478
|
+
]);
|
|
2464
2479
|
}
|
|
2465
2480
|
});
|
|
2466
2481
|
api.modifyWebpackConfig(async (config) => {
|
|
@@ -2489,10 +2504,6 @@ __export(build_exports, {
|
|
|
2489
2504
|
build: () => build
|
|
2490
2505
|
});
|
|
2491
2506
|
import { logger as logger6 } from "@rsbuild/core";
|
|
2492
|
-
import {
|
|
2493
|
-
getNodeEnv as getNodeEnv2,
|
|
2494
|
-
setNodeEnv as setNodeEnv2
|
|
2495
|
-
} from "@rsbuild/shared";
|
|
2496
2507
|
import WebpackMultiStats2 from "webpack/lib/MultiStats.js";
|
|
2497
2508
|
var build;
|
|
2498
2509
|
var init_build = __esm({
|
|
@@ -2503,8 +2514,8 @@ var init_build = __esm({
|
|
|
2503
2514
|
init_initConfigs();
|
|
2504
2515
|
init_shared();
|
|
2505
2516
|
build = async (initOptions, { mode = "production", watch, compiler: customCompiler } = {}) => {
|
|
2506
|
-
if (!
|
|
2507
|
-
|
|
2517
|
+
if (!process.env.NODE_ENV) {
|
|
2518
|
+
process.env.NODE_ENV = mode;
|
|
2508
2519
|
}
|
|
2509
2520
|
const { context } = initOptions;
|
|
2510
2521
|
let compiler;
|
|
@@ -2521,10 +2532,15 @@ var init_build = __esm({
|
|
|
2521
2532
|
}
|
|
2522
2533
|
let isFirstCompile = true;
|
|
2523
2534
|
await context.hooks.onBeforeBuild.call({
|
|
2524
|
-
bundlerConfigs
|
|
2535
|
+
bundlerConfigs,
|
|
2536
|
+
environments: context.environments
|
|
2525
2537
|
});
|
|
2526
2538
|
const onDone = async (stats) => {
|
|
2527
|
-
const p = context.hooks.onAfterBuild.call({
|
|
2539
|
+
const p = context.hooks.onAfterBuild.call({
|
|
2540
|
+
isFirstCompile,
|
|
2541
|
+
stats,
|
|
2542
|
+
environments: context.environments
|
|
2543
|
+
});
|
|
2528
2544
|
isFirstCompile = false;
|
|
2529
2545
|
await p;
|
|
2530
2546
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type CreateRsbuildOptions } from '@rsbuild/core';
|
|
2
|
+
import type { PluginManager } from '@rsbuild/shared';
|
|
3
|
+
import { type InternalContext } from './shared';
|
|
4
|
+
import type { WebpackConfig } from './types';
|
|
5
|
+
export type InitConfigsOptions = {
|
|
6
|
+
context: InternalContext;
|
|
7
|
+
pluginManager: PluginManager;
|
|
8
|
+
rsbuildOptions: Required<CreateRsbuildOptions>;
|
|
9
|
+
};
|
|
10
|
+
export declare function initConfigs({ context, pluginManager, rsbuildOptions, }: InitConfigsOptions): Promise<{
|
|
11
|
+
webpackConfigs: WebpackConfig[];
|
|
12
|
+
}>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { InspectConfigOptions, InspectConfigResult } from '@rsbuild/core';
|
|
2
|
+
import { type InitConfigsOptions } from './initConfigs';
|
|
3
|
+
import type { WebpackConfig } from './types';
|
|
4
|
+
export declare function inspectConfig({ context, pluginManager, rsbuildOptions, bundlerConfigs, inspectOptions, }: InitConfigsOptions & {
|
|
5
|
+
inspectOptions?: InspectConfigOptions;
|
|
6
|
+
bundlerConfigs?: WebpackConfig[];
|
|
7
|
+
}): Promise<InspectConfigResult<'webpack'>>;
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import webpack from 'webpack';
|
|
2
|
+
import type { Props } from './helpers/type';
|
|
3
|
+
export interface ProgressOptions extends Omit<Partial<Props>, 'message' | 'total' | 'current' | 'done'> {
|
|
4
|
+
id?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare class ProgressPlugin extends webpack.ProgressPlugin {
|
|
7
|
+
readonly name: string;
|
|
8
|
+
id: string;
|
|
9
|
+
hasCompileErrors: boolean;
|
|
10
|
+
compileTime: string | null;
|
|
11
|
+
constructor(options: ProgressOptions);
|
|
12
|
+
apply(compiler: webpack.Compiler): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Colors } from '@rsbuild/shared';
|
|
2
|
+
import type { LogUpdate } from './log';
|
|
3
|
+
import type { Props } from './type';
|
|
4
|
+
export declare const getProgressColor: (index: number) => Colors;
|
|
5
|
+
declare class Bus {
|
|
6
|
+
states: Partial<Props>[];
|
|
7
|
+
log: LogUpdate;
|
|
8
|
+
restore: () => void;
|
|
9
|
+
prevOutput: string;
|
|
10
|
+
destroyed: boolean;
|
|
11
|
+
constructor();
|
|
12
|
+
update(state: Partial<Props>): void;
|
|
13
|
+
writeToStd(type?: 'stdout' | 'stderr', data?: string): void;
|
|
14
|
+
render(): void;
|
|
15
|
+
destroy(): void;
|
|
16
|
+
clear(): void;
|
|
17
|
+
}
|
|
18
|
+
declare const bus: Bus;
|
|
19
|
+
export { bus };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Make the progress percentage more user friendly.
|
|
3
|
+
* The original percentage may pause at certain number for a long time,
|
|
4
|
+
* or decrease in some cases, which will confuse the user.
|
|
5
|
+
* So we format the percentage number and display a more smooth percentage.
|
|
6
|
+
*/
|
|
7
|
+
export declare const createFriendlyPercentage: () => (percentage: number) => number;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Colors } from '@rsbuild/shared';
|
|
2
|
+
export type Props = {
|
|
3
|
+
total: number;
|
|
4
|
+
current: number;
|
|
5
|
+
color: Colors;
|
|
6
|
+
bgColor: Colors;
|
|
7
|
+
char: string;
|
|
8
|
+
width: number;
|
|
9
|
+
buildIcon: string;
|
|
10
|
+
errorIcon: string;
|
|
11
|
+
errorInfo: string;
|
|
12
|
+
message: string;
|
|
13
|
+
done: boolean;
|
|
14
|
+
messageWidth: number;
|
|
15
|
+
spaceWidth: number;
|
|
16
|
+
messageColor: Colors;
|
|
17
|
+
id: string;
|
|
18
|
+
maxIdLen: number;
|
|
19
|
+
hasErrors: boolean;
|
|
20
|
+
};
|
|
21
|
+
export type BusOption = {
|
|
22
|
+
state: Props[];
|
|
23
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const clamp: (x: number, min: number, max: number) => number;
|
package/dist/shared.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { __internalHelper } from '@rsbuild/core';
|
|
2
|
+
declare const getChainUtils: typeof __internalHelper.getChainUtils, initRsbuildConfig: typeof __internalHelper.initRsbuildConfig, createDevServer: typeof __internalHelper.createDevServer, formatStats: typeof __internalHelper.formatStats, getDevMiddleware: (multiCompiler: import("@rspack/core").Compiler | import("@rspack/core").MultiCompiler) => Promise<NonNullable<import("node_modules/@rsbuild/core/dist-types/server/devMiddleware").DevMiddleware>>, getStatsOptions: typeof __internalHelper.getStatsOptions, stringifyConfig: typeof __internalHelper.stringifyConfig, outputInspectConfigFiles: typeof __internalHelper.outputInspectConfigFiles, getRsbuildInspectConfig: ({ normalizedConfig, inspectOptions, pluginManager, }: {
|
|
3
|
+
normalizedConfig: import("@rsbuild/core").NormalizedConfig;
|
|
4
|
+
inspectOptions: import("@rsbuild/core").InspectConfigOptions;
|
|
5
|
+
pluginManager: import("@rsbuild/shared").PluginManager;
|
|
6
|
+
}) => {
|
|
7
|
+
rawRsbuildConfig: string;
|
|
8
|
+
rsbuildConfig: import("@rsbuild/core").InspectConfigResult["origin"]["rsbuildConfig"];
|
|
9
|
+
rawEnvironmentConfigs: Array<{
|
|
10
|
+
name: string;
|
|
11
|
+
content: string;
|
|
12
|
+
}>;
|
|
13
|
+
environmentConfigs: import("@rsbuild/core").InspectConfigResult["origin"]["environmentConfigs"];
|
|
14
|
+
}, chainToConfig: typeof __internalHelper.chainToConfig, modifyBundlerChain: typeof __internalHelper.modifyBundlerChain, onCompileDone: (compiler: import("@rspack/core").Compiler | import("@rspack/core").MultiCompiler, onDone: (stats: import("@rsbuild/shared").Stats | import("@rsbuild/shared").MultiStats) => Promise<void>, MultiStatsCtor: new (stats: import("@rsbuild/shared").Stats[]) => import("@rsbuild/shared").MultiStats) => void, prettyTime: (seconds: number) => string;
|
|
15
|
+
export { getChainUtils, initRsbuildConfig, createDevServer, formatStats, getDevMiddleware, getStatsOptions, stringifyConfig, outputInspectConfigFiles, chainToConfig, modifyBundlerChain, onCompileDone, prettyTime, getRsbuildInspectConfig, };
|
|
16
|
+
export type InternalContext = __internalHelper.InternalContext;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type RsbuildTarget } from '@rsbuild/core';
|
|
2
|
+
import { type InternalContext } from './shared';
|
|
3
|
+
import type { WebpackConfig } from './types';
|
|
4
|
+
export declare function generateWebpackConfig({ target, context, environment, }: {
|
|
5
|
+
environment: string;
|
|
6
|
+
target: RsbuildTarget;
|
|
7
|
+
context: InternalContext;
|
|
8
|
+
}): Promise<WebpackConfig>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/webpack",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-alpha.1",
|
|
4
4
|
"homepage": "https://rsbuild.dev",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -23,20 +23,21 @@
|
|
|
23
23
|
"dist"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"copy-webpack-plugin": "
|
|
26
|
+
"copy-webpack-plugin": "11.0.0",
|
|
27
27
|
"mini-css-extract-plugin": "2.9.0",
|
|
28
|
+
"reduce-configs": "^1.0.0",
|
|
28
29
|
"tsconfig-paths-webpack-plugin": "4.1.0",
|
|
29
|
-
"webpack": "^5.92.
|
|
30
|
-
"@rsbuild/core": "0.
|
|
31
|
-
"@rsbuild/shared": "0.
|
|
30
|
+
"webpack": "^5.92.1",
|
|
31
|
+
"@rsbuild/core": "1.0.0-alpha.1",
|
|
32
|
+
"@rsbuild/shared": "1.0.0-alpha.1"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
35
|
"@types/node": "18.x",
|
|
35
36
|
"ansi-escapes": "4.3.2",
|
|
36
37
|
"cli-truncate": "2.1.0",
|
|
37
38
|
"patch-console": "1.0.0",
|
|
38
|
-
"typescript": "^5.
|
|
39
|
-
"@scripts/test-helper": "0.
|
|
39
|
+
"typescript": "^5.5.2",
|
|
40
|
+
"@scripts/test-helper": "1.0.0-alpha.1"
|
|
40
41
|
},
|
|
41
42
|
"publishConfig": {
|
|
42
43
|
"access": "public",
|