@rsbuild/webpack 0.7.10 → 1.0.0-alpha.0
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 +102 -85
- package/dist/index.d.ts +2 -6
- package/dist/index.js +88 -74
- 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 +7 -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_core2.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,12 @@ async function generateWebpackConfig({
|
|
|
249
254
|
);
|
|
250
255
|
return webpackConfig;
|
|
251
256
|
}
|
|
252
|
-
var import_core2,
|
|
257
|
+
var import_core2, import_shared2;
|
|
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");
|
|
258
263
|
init_shared();
|
|
259
264
|
}
|
|
260
265
|
});
|
|
@@ -269,9 +274,14 @@ async function initConfigs({
|
|
|
269
274
|
context,
|
|
270
275
|
pluginManager
|
|
271
276
|
});
|
|
272
|
-
const { targets } = normalizedConfig.output;
|
|
273
277
|
const webpackConfigs = await Promise.all(
|
|
274
|
-
|
|
278
|
+
Object.entries(normalizedConfig.environments).map(
|
|
279
|
+
([environment, config]) => generateWebpackConfig({
|
|
280
|
+
target: config.output.target,
|
|
281
|
+
context,
|
|
282
|
+
environment
|
|
283
|
+
})
|
|
284
|
+
)
|
|
275
285
|
);
|
|
276
286
|
if (import_core3.logger.level === "verbose") {
|
|
277
287
|
const inspect = () => {
|
|
@@ -332,7 +342,7 @@ async function createCompiler({
|
|
|
332
342
|
if (level === "warning") {
|
|
333
343
|
import_core4.logger.warn(message);
|
|
334
344
|
}
|
|
335
|
-
if (
|
|
345
|
+
if (process.env.NODE_ENV === "development") {
|
|
336
346
|
await context.hooks.onDevCompileDone.call({
|
|
337
347
|
isFirstCompile,
|
|
338
348
|
stats
|
|
@@ -343,7 +353,8 @@ async function createCompiler({
|
|
|
343
353
|
let isFirstCompile = true;
|
|
344
354
|
onCompileDone(compiler, done, import_MultiStats.default);
|
|
345
355
|
await context.hooks.onAfterCreateCompiler.call({
|
|
346
|
-
compiler
|
|
356
|
+
compiler,
|
|
357
|
+
environments: context.environments
|
|
347
358
|
});
|
|
348
359
|
import_core4.logger.debug("create compiler done");
|
|
349
360
|
return compiler;
|
|
@@ -364,12 +375,11 @@ async function createDevMiddleware(options, customCompiler) {
|
|
|
364
375
|
compiler
|
|
365
376
|
};
|
|
366
377
|
}
|
|
367
|
-
var import_core4,
|
|
378
|
+
var import_core4, import_MultiStats;
|
|
368
379
|
var init_createCompiler = __esm({
|
|
369
380
|
"src/createCompiler.ts"() {
|
|
370
381
|
"use strict";
|
|
371
382
|
import_core4 = require("@rsbuild/core");
|
|
372
|
-
import_shared6 = require("@rsbuild/shared");
|
|
373
383
|
import_MultiStats = __toESM(require("webpack/lib/MultiStats.js"));
|
|
374
384
|
init_initConfigs();
|
|
375
385
|
init_shared();
|
|
@@ -1030,18 +1040,18 @@ var require_conversions = __commonJS({
|
|
|
1030
1040
|
return ansi;
|
|
1031
1041
|
};
|
|
1032
1042
|
convert.ansi16.rgb = function(args) {
|
|
1033
|
-
let
|
|
1034
|
-
if (
|
|
1043
|
+
let color3 = args % 10;
|
|
1044
|
+
if (color3 === 0 || color3 === 7) {
|
|
1035
1045
|
if (args > 50) {
|
|
1036
|
-
|
|
1046
|
+
color3 += 3.5;
|
|
1037
1047
|
}
|
|
1038
|
-
|
|
1039
|
-
return [
|
|
1048
|
+
color3 = color3 / 10.5 * 255;
|
|
1049
|
+
return [color3, color3, color3];
|
|
1040
1050
|
}
|
|
1041
1051
|
const mult = (~~(args > 50) + 1) * 0.5;
|
|
1042
|
-
const r = (
|
|
1043
|
-
const g = (
|
|
1044
|
-
const b = (
|
|
1052
|
+
const r = (color3 & 1) * mult * 255;
|
|
1053
|
+
const g = (color3 >> 1 & 1) * mult * 255;
|
|
1054
|
+
const b = (color3 >> 2 & 1) * mult * 255;
|
|
1045
1055
|
return [r, g, b];
|
|
1046
1056
|
};
|
|
1047
1057
|
convert.ansi256.rgb = function(args) {
|
|
@@ -1826,11 +1836,11 @@ var init_utils = __esm({
|
|
|
1826
1836
|
});
|
|
1827
1837
|
|
|
1828
1838
|
// src/progress/helpers/bar.ts
|
|
1829
|
-
var
|
|
1839
|
+
var import_shared7, import_cli_truncate, defaultOption, padding, FULL_WIDTH, MIDDLE_WIDTH, renderBar;
|
|
1830
1840
|
var init_bar = __esm({
|
|
1831
1841
|
"src/progress/helpers/bar.ts"() {
|
|
1832
1842
|
"use strict";
|
|
1833
|
-
|
|
1843
|
+
import_shared7 = require("@rsbuild/shared");
|
|
1834
1844
|
import_cli_truncate = __toESM(require_cli_truncate());
|
|
1835
1845
|
init_utils();
|
|
1836
1846
|
defaultOption = {
|
|
@@ -1872,7 +1882,7 @@ var init_bar = __esm({
|
|
|
1872
1882
|
errorInfo,
|
|
1873
1883
|
width,
|
|
1874
1884
|
current,
|
|
1875
|
-
color,
|
|
1885
|
+
color: color3,
|
|
1876
1886
|
bgColor,
|
|
1877
1887
|
char,
|
|
1878
1888
|
message,
|
|
@@ -1884,15 +1894,15 @@ var init_bar = __esm({
|
|
|
1884
1894
|
} = mergedOptions;
|
|
1885
1895
|
const space = " ".repeat(spaceWidth);
|
|
1886
1896
|
const percent = clamp(Math.floor(current / total * 100), 0, 100);
|
|
1887
|
-
const barColor =
|
|
1888
|
-
const backgroundColor =
|
|
1889
|
-
const doneColor = hasErrors ?
|
|
1897
|
+
const barColor = import_shared7.color[color3];
|
|
1898
|
+
const backgroundColor = import_shared7.color[bgColor];
|
|
1899
|
+
const doneColor = hasErrors ? import_shared7.color.red : barColor;
|
|
1890
1900
|
const idColor = done ? doneColor : barColor;
|
|
1891
1901
|
const id = mergedOptions.id ? idColor(padding(mergedOptions.id, maxIdLen)) : "";
|
|
1892
1902
|
const { columns: terminalWidth = FULL_WIDTH } = process.stdout;
|
|
1893
1903
|
if (done) {
|
|
1894
1904
|
if (hasErrors) {
|
|
1895
|
-
const message2 =
|
|
1905
|
+
const message2 = import_shared7.color.bold(doneColor(errorInfo));
|
|
1896
1906
|
if (terminalWidth >= MIDDLE_WIDTH) {
|
|
1897
1907
|
return [idColor(errorIcon), id, doneColor(`${space}${message2}`)].join(
|
|
1898
1908
|
""
|
|
@@ -1902,7 +1912,7 @@ var init_bar = __esm({
|
|
|
1902
1912
|
}
|
|
1903
1913
|
return "";
|
|
1904
1914
|
}
|
|
1905
|
-
const msgStr =
|
|
1915
|
+
const msgStr = import_shared7.color[messageColor](
|
|
1906
1916
|
(0, import_cli_truncate.default)(message, messageWidth, { position: "start" })
|
|
1907
1917
|
);
|
|
1908
1918
|
const left = clamp(Math.floor(percent * width / 100), 0, width);
|
|
@@ -2228,30 +2238,32 @@ function createNonTTYLogger() {
|
|
|
2228
2238
|
hasErrors,
|
|
2229
2239
|
compileTime
|
|
2230
2240
|
}) => {
|
|
2241
|
+
const suffix = import_shared8.color.gray(`(${id})`);
|
|
2231
2242
|
if (done) {
|
|
2232
2243
|
if (prevPercentage === 100) {
|
|
2233
2244
|
return;
|
|
2234
2245
|
}
|
|
2235
2246
|
prevPercentage = 100;
|
|
2236
2247
|
if (hasErrors) {
|
|
2237
|
-
import_core5.logger.error(
|
|
2248
|
+
import_core5.logger.error(`Compile failed in ${compileTime} ${suffix}`);
|
|
2238
2249
|
} else {
|
|
2239
|
-
import_core5.logger.ready(
|
|
2250
|
+
import_core5.logger.ready(`Compiled in ${compileTime} ${suffix}`);
|
|
2240
2251
|
}
|
|
2241
2252
|
} else if (current - prevPercentage > 10) {
|
|
2242
2253
|
prevPercentage = current;
|
|
2243
|
-
import_core5.logger.info(
|
|
2254
|
+
import_core5.logger.info(`Compile progress: ${current.toFixed(0)}% ${suffix}`);
|
|
2244
2255
|
}
|
|
2245
2256
|
};
|
|
2246
2257
|
return {
|
|
2247
2258
|
log
|
|
2248
2259
|
};
|
|
2249
2260
|
}
|
|
2250
|
-
var import_core5;
|
|
2261
|
+
var import_core5, import_shared8;
|
|
2251
2262
|
var init_nonTty = __esm({
|
|
2252
2263
|
"src/progress/helpers/nonTty.ts"() {
|
|
2253
2264
|
"use strict";
|
|
2254
2265
|
import_core5 = require("@rsbuild/core");
|
|
2266
|
+
import_shared8 = require("@rsbuild/shared");
|
|
2255
2267
|
}
|
|
2256
2268
|
});
|
|
2257
2269
|
|
|
@@ -2260,13 +2272,14 @@ var ProgressPlugin_exports = {};
|
|
|
2260
2272
|
__export(ProgressPlugin_exports, {
|
|
2261
2273
|
ProgressPlugin: () => ProgressPlugin
|
|
2262
2274
|
});
|
|
2263
|
-
var import_core6,
|
|
2275
|
+
var import_core6, import_shared9, import_webpack, ProgressPlugin;
|
|
2264
2276
|
var init_ProgressPlugin = __esm({
|
|
2265
2277
|
"src/progress/ProgressPlugin.ts"() {
|
|
2266
2278
|
"use strict";
|
|
2267
2279
|
import_core6 = require("@rsbuild/core");
|
|
2268
|
-
|
|
2280
|
+
import_shared9 = require("@rsbuild/shared");
|
|
2269
2281
|
import_webpack = __toESM(require("webpack"));
|
|
2282
|
+
init_shared();
|
|
2270
2283
|
init_helpers();
|
|
2271
2284
|
init_nonTty();
|
|
2272
2285
|
ProgressPlugin = class extends import_webpack.default.ProgressPlugin {
|
|
@@ -2324,10 +2337,11 @@ var init_ProgressPlugin = __esm({
|
|
|
2324
2337
|
this.hasCompileErrors = stat.hasErrors();
|
|
2325
2338
|
const hrtime = process.hrtime(startTime);
|
|
2326
2339
|
const seconds = hrtime[0] + hrtime[1] / 1e9;
|
|
2327
|
-
this.compileTime =
|
|
2340
|
+
this.compileTime = prettyTime(seconds);
|
|
2328
2341
|
startTime = null;
|
|
2329
2342
|
if (!this.hasCompileErrors) {
|
|
2330
|
-
|
|
2343
|
+
const suffix = this.id ? import_shared9.color.gray(` (${this.id})`) : "";
|
|
2344
|
+
import_core6.logger.ready(`Compiled in ${this.compileTime} ${suffix}`);
|
|
2331
2345
|
}
|
|
2332
2346
|
}
|
|
2333
2347
|
});
|
|
@@ -2368,7 +2382,6 @@ var init_plugin = __esm({
|
|
|
2368
2382
|
"use strict";
|
|
2369
2383
|
import_node_fs = __toESM(require("fs"));
|
|
2370
2384
|
import_shared11 = require("@rsbuild/shared");
|
|
2371
|
-
init_shared();
|
|
2372
2385
|
getMainFields = (chain, target) => {
|
|
2373
2386
|
const mainFields = chain.resolve.mainFields.values();
|
|
2374
2387
|
if (mainFields.length) {
|
|
@@ -2382,13 +2395,13 @@ var init_plugin = __esm({
|
|
|
2382
2395
|
pluginAdaptor = () => ({
|
|
2383
2396
|
name: "rsbuild-webpack:adaptor",
|
|
2384
2397
|
setup(api) {
|
|
2385
|
-
api.modifyBundlerChain(async (chain, { CHAIN_ID, target }) => {
|
|
2386
|
-
const config =
|
|
2387
|
-
if (
|
|
2398
|
+
api.modifyBundlerChain(async (chain, { CHAIN_ID, environment, target }) => {
|
|
2399
|
+
const { config, tsconfigPath } = environment;
|
|
2400
|
+
if (tsconfigPath && config.source.aliasStrategy === "prefer-tsconfig") {
|
|
2388
2401
|
await applyTsConfigPathsPlugin({
|
|
2389
2402
|
chain,
|
|
2390
2403
|
CHAIN_ID,
|
|
2391
|
-
configFile:
|
|
2404
|
+
configFile: tsconfigPath,
|
|
2392
2405
|
mainFields: getMainFields(chain, target),
|
|
2393
2406
|
extensions: chain.resolve.extensions.values()
|
|
2394
2407
|
});
|
|
@@ -2398,19 +2411,19 @@ var init_plugin = __esm({
|
|
|
2398
2411
|
const { ProgressPlugin: ProgressPlugin2 } = await Promise.resolve().then(() => (init_ProgressPlugin(), ProgressPlugin_exports));
|
|
2399
2412
|
chain.plugin(CHAIN_ID.PLUGIN.PROGRESS).use(ProgressPlugin2, [
|
|
2400
2413
|
{
|
|
2401
|
-
id:
|
|
2414
|
+
id: environment.name,
|
|
2402
2415
|
...progress === true ? {} : progress
|
|
2403
2416
|
}
|
|
2404
2417
|
]);
|
|
2405
2418
|
}
|
|
2406
2419
|
const { copy } = config.output;
|
|
2407
2420
|
if (copy) {
|
|
2408
|
-
const { default: CopyPlugin } = await import(
|
|
2409
|
-
// @ts-expect-error copy-webpack-plugin does not provide types
|
|
2410
|
-
"copy-webpack-plugin"
|
|
2411
|
-
);
|
|
2421
|
+
const { default: CopyPlugin } = await import("copy-webpack-plugin");
|
|
2412
2422
|
const options = Array.isArray(copy) ? { patterns: copy } : copy;
|
|
2413
|
-
chain.plugin(CHAIN_ID.PLUGIN.COPY).use(CopyPlugin, [
|
|
2423
|
+
chain.plugin(CHAIN_ID.PLUGIN.COPY).use(CopyPlugin, [
|
|
2424
|
+
// @ts-expect-error to type mismatch
|
|
2425
|
+
options
|
|
2426
|
+
]);
|
|
2414
2427
|
}
|
|
2415
2428
|
});
|
|
2416
2429
|
api.modifyWebpackConfig(async (config) => {
|
|
@@ -2438,19 +2451,18 @@ var build_exports = {};
|
|
|
2438
2451
|
__export(build_exports, {
|
|
2439
2452
|
build: () => build
|
|
2440
2453
|
});
|
|
2441
|
-
var import_core7,
|
|
2454
|
+
var import_core7, import_MultiStats2, build;
|
|
2442
2455
|
var init_build = __esm({
|
|
2443
2456
|
"src/build.ts"() {
|
|
2444
2457
|
"use strict";
|
|
2445
2458
|
import_core7 = require("@rsbuild/core");
|
|
2446
|
-
import_shared13 = require("@rsbuild/shared");
|
|
2447
2459
|
import_MultiStats2 = __toESM(require("webpack/lib/MultiStats.js"));
|
|
2448
2460
|
init_createCompiler();
|
|
2449
2461
|
init_initConfigs();
|
|
2450
2462
|
init_shared();
|
|
2451
2463
|
build = async (initOptions, { mode = "production", watch, compiler: customCompiler } = {}) => {
|
|
2452
|
-
if (!
|
|
2453
|
-
|
|
2464
|
+
if (!process.env.NODE_ENV) {
|
|
2465
|
+
process.env.NODE_ENV = mode;
|
|
2454
2466
|
}
|
|
2455
2467
|
const { context } = initOptions;
|
|
2456
2468
|
let compiler;
|
|
@@ -2467,10 +2479,15 @@ var init_build = __esm({
|
|
|
2467
2479
|
}
|
|
2468
2480
|
let isFirstCompile = true;
|
|
2469
2481
|
await context.hooks.onBeforeBuild.call({
|
|
2470
|
-
bundlerConfigs
|
|
2482
|
+
bundlerConfigs,
|
|
2483
|
+
environments: context.environments
|
|
2471
2484
|
});
|
|
2472
2485
|
const onDone = async (stats) => {
|
|
2473
|
-
const p = context.hooks.onAfterBuild.call({
|
|
2486
|
+
const p = context.hooks.onAfterBuild.call({
|
|
2487
|
+
isFirstCompile,
|
|
2488
|
+
stats,
|
|
2489
|
+
environments: context.environments
|
|
2490
|
+
});
|
|
2474
2491
|
isFirstCompile = false;
|
|
2475
2492
|
await p;
|
|
2476
2493
|
};
|
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
|
};
|
|
@@ -153,11 +155,11 @@ var init_inspectConfig = __esm({
|
|
|
153
155
|
// src/webpackConfig.ts
|
|
154
156
|
import {
|
|
155
157
|
__internalHelper as __internalHelper2,
|
|
156
|
-
logger
|
|
158
|
+
logger,
|
|
159
|
+
reduceConfigsWithContext
|
|
157
160
|
} from "@rsbuild/core";
|
|
158
161
|
import {
|
|
159
|
-
castArray
|
|
160
|
-
reduceConfigsWithContext
|
|
162
|
+
castArray
|
|
161
163
|
} from "@rsbuild/shared";
|
|
162
164
|
async function modifyWebpackChain(context, utils, chain) {
|
|
163
165
|
logger.debug("modify webpack chain");
|
|
@@ -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,
|
|
@@ -361,7 +370,7 @@ async function createCompiler({
|
|
|
361
370
|
if (level === "warning") {
|
|
362
371
|
logger3.warn(message);
|
|
363
372
|
}
|
|
364
|
-
if (
|
|
373
|
+
if (process.env.NODE_ENV === "development") {
|
|
365
374
|
await context.hooks.onDevCompileDone.call({
|
|
366
375
|
isFirstCompile,
|
|
367
376
|
stats
|
|
@@ -372,7 +381,8 @@ async function createCompiler({
|
|
|
372
381
|
let isFirstCompile = true;
|
|
373
382
|
onCompileDone(compiler, done, WebpackMultiStats);
|
|
374
383
|
await context.hooks.onAfterCreateCompiler.call({
|
|
375
|
-
compiler
|
|
384
|
+
compiler,
|
|
385
|
+
environments: context.environments
|
|
376
386
|
});
|
|
377
387
|
logger3.debug("create compiler done");
|
|
378
388
|
return compiler;
|
|
@@ -1060,18 +1070,18 @@ var require_conversions = __commonJS({
|
|
|
1060
1070
|
return ansi;
|
|
1061
1071
|
};
|
|
1062
1072
|
convert.ansi16.rgb = function(args) {
|
|
1063
|
-
let
|
|
1064
|
-
if (
|
|
1073
|
+
let color3 = args % 10;
|
|
1074
|
+
if (color3 === 0 || color3 === 7) {
|
|
1065
1075
|
if (args > 50) {
|
|
1066
|
-
|
|
1076
|
+
color3 += 3.5;
|
|
1067
1077
|
}
|
|
1068
|
-
|
|
1069
|
-
return [
|
|
1078
|
+
color3 = color3 / 10.5 * 255;
|
|
1079
|
+
return [color3, color3, color3];
|
|
1070
1080
|
}
|
|
1071
1081
|
const mult = (~~(args > 50) + 1) * 0.5;
|
|
1072
|
-
const r = (
|
|
1073
|
-
const g = (
|
|
1074
|
-
const b = (
|
|
1082
|
+
const r = (color3 & 1) * mult * 255;
|
|
1083
|
+
const g = (color3 >> 1 & 1) * mult * 255;
|
|
1084
|
+
const b = (color3 >> 2 & 1) * mult * 255;
|
|
1075
1085
|
return [r, g, b];
|
|
1076
1086
|
};
|
|
1077
1087
|
convert.ansi256.rgb = function(args) {
|
|
@@ -1914,7 +1924,7 @@ var init_bar = __esm({
|
|
|
1914
1924
|
errorInfo,
|
|
1915
1925
|
width,
|
|
1916
1926
|
current,
|
|
1917
|
-
color,
|
|
1927
|
+
color: color3,
|
|
1918
1928
|
bgColor,
|
|
1919
1929
|
char,
|
|
1920
1930
|
message,
|
|
@@ -1926,7 +1936,7 @@ var init_bar = __esm({
|
|
|
1926
1936
|
} = mergedOptions;
|
|
1927
1937
|
const space = " ".repeat(spaceWidth);
|
|
1928
1938
|
const percent = clamp(Math.floor(current / total * 100), 0, 100);
|
|
1929
|
-
const barColor = colors[
|
|
1939
|
+
const barColor = colors[color3];
|
|
1930
1940
|
const backgroundColor = colors[bgColor];
|
|
1931
1941
|
const doneColor = hasErrors ? colors.red : barColor;
|
|
1932
1942
|
const idColor = done ? doneColor : barColor;
|
|
@@ -2268,6 +2278,7 @@ var init_helpers = __esm({
|
|
|
2268
2278
|
|
|
2269
2279
|
// src/progress/helpers/nonTty.ts
|
|
2270
2280
|
import { logger as logger4 } from "@rsbuild/core";
|
|
2281
|
+
import { color } from "@rsbuild/shared";
|
|
2271
2282
|
function createNonTTYLogger() {
|
|
2272
2283
|
let prevPercentage = 0;
|
|
2273
2284
|
const log = ({
|
|
@@ -2277,19 +2288,20 @@ function createNonTTYLogger() {
|
|
|
2277
2288
|
hasErrors,
|
|
2278
2289
|
compileTime
|
|
2279
2290
|
}) => {
|
|
2291
|
+
const suffix = color.gray(`(${id})`);
|
|
2280
2292
|
if (done) {
|
|
2281
2293
|
if (prevPercentage === 100) {
|
|
2282
2294
|
return;
|
|
2283
2295
|
}
|
|
2284
2296
|
prevPercentage = 100;
|
|
2285
2297
|
if (hasErrors) {
|
|
2286
|
-
logger4.error(
|
|
2298
|
+
logger4.error(`Compile failed in ${compileTime} ${suffix}`);
|
|
2287
2299
|
} else {
|
|
2288
|
-
logger4.ready(
|
|
2300
|
+
logger4.ready(`Compiled in ${compileTime} ${suffix}`);
|
|
2289
2301
|
}
|
|
2290
2302
|
} else if (current - prevPercentage > 10) {
|
|
2291
2303
|
prevPercentage = current;
|
|
2292
|
-
logger4.info(
|
|
2304
|
+
logger4.info(`Compile progress: ${current.toFixed(0)}% ${suffix}`);
|
|
2293
2305
|
}
|
|
2294
2306
|
};
|
|
2295
2307
|
return {
|
|
@@ -2309,13 +2321,14 @@ __export(ProgressPlugin_exports, {
|
|
|
2309
2321
|
ProgressPlugin: () => ProgressPlugin
|
|
2310
2322
|
});
|
|
2311
2323
|
import { logger as logger5 } from "@rsbuild/core";
|
|
2312
|
-
import {
|
|
2324
|
+
import { color as color2 } from "@rsbuild/shared";
|
|
2313
2325
|
import webpack from "webpack";
|
|
2314
2326
|
var ProgressPlugin;
|
|
2315
2327
|
var init_ProgressPlugin = __esm({
|
|
2316
2328
|
"src/progress/ProgressPlugin.ts"() {
|
|
2317
2329
|
"use strict";
|
|
2318
2330
|
init_esm();
|
|
2331
|
+
init_shared();
|
|
2319
2332
|
init_helpers();
|
|
2320
2333
|
init_nonTty();
|
|
2321
2334
|
ProgressPlugin = class extends webpack.ProgressPlugin {
|
|
@@ -2376,7 +2389,8 @@ var init_ProgressPlugin = __esm({
|
|
|
2376
2389
|
this.compileTime = prettyTime(seconds);
|
|
2377
2390
|
startTime = null;
|
|
2378
2391
|
if (!this.hasCompileErrors) {
|
|
2379
|
-
|
|
2392
|
+
const suffix = this.id ? color2.gray(` (${this.id})`) : "";
|
|
2393
|
+
logger5.ready(`Compiled in ${this.compileTime} ${suffix}`);
|
|
2380
2394
|
}
|
|
2381
2395
|
}
|
|
2382
2396
|
});
|
|
@@ -2418,7 +2432,6 @@ var init_plugin = __esm({
|
|
|
2418
2432
|
"src/plugin.ts"() {
|
|
2419
2433
|
"use strict";
|
|
2420
2434
|
init_esm();
|
|
2421
|
-
init_shared();
|
|
2422
2435
|
getMainFields = (chain, target) => {
|
|
2423
2436
|
const mainFields = chain.resolve.mainFields.values();
|
|
2424
2437
|
if (mainFields.length) {
|
|
@@ -2432,13 +2445,13 @@ var init_plugin = __esm({
|
|
|
2432
2445
|
pluginAdaptor = () => ({
|
|
2433
2446
|
name: "rsbuild-webpack:adaptor",
|
|
2434
2447
|
setup(api) {
|
|
2435
|
-
api.modifyBundlerChain(async (chain, { CHAIN_ID, target }) => {
|
|
2436
|
-
const config =
|
|
2437
|
-
if (
|
|
2448
|
+
api.modifyBundlerChain(async (chain, { CHAIN_ID, environment, target }) => {
|
|
2449
|
+
const { config, tsconfigPath } = environment;
|
|
2450
|
+
if (tsconfigPath && config.source.aliasStrategy === "prefer-tsconfig") {
|
|
2438
2451
|
await applyTsConfigPathsPlugin({
|
|
2439
2452
|
chain,
|
|
2440
2453
|
CHAIN_ID,
|
|
2441
|
-
configFile:
|
|
2454
|
+
configFile: tsconfigPath,
|
|
2442
2455
|
mainFields: getMainFields(chain, target),
|
|
2443
2456
|
extensions: chain.resolve.extensions.values()
|
|
2444
2457
|
});
|
|
@@ -2448,19 +2461,19 @@ var init_plugin = __esm({
|
|
|
2448
2461
|
const { ProgressPlugin: ProgressPlugin2 } = await Promise.resolve().then(() => (init_ProgressPlugin(), ProgressPlugin_exports));
|
|
2449
2462
|
chain.plugin(CHAIN_ID.PLUGIN.PROGRESS).use(ProgressPlugin2, [
|
|
2450
2463
|
{
|
|
2451
|
-
id:
|
|
2464
|
+
id: environment.name,
|
|
2452
2465
|
...progress === true ? {} : progress
|
|
2453
2466
|
}
|
|
2454
2467
|
]);
|
|
2455
2468
|
}
|
|
2456
2469
|
const { copy } = config.output;
|
|
2457
2470
|
if (copy) {
|
|
2458
|
-
const { default: CopyPlugin } = await import(
|
|
2459
|
-
// @ts-expect-error copy-webpack-plugin does not provide types
|
|
2460
|
-
"copy-webpack-plugin"
|
|
2461
|
-
);
|
|
2471
|
+
const { default: CopyPlugin } = await import("copy-webpack-plugin");
|
|
2462
2472
|
const options = Array.isArray(copy) ? { patterns: copy } : copy;
|
|
2463
|
-
chain.plugin(CHAIN_ID.PLUGIN.COPY).use(CopyPlugin, [
|
|
2473
|
+
chain.plugin(CHAIN_ID.PLUGIN.COPY).use(CopyPlugin, [
|
|
2474
|
+
// @ts-expect-error to type mismatch
|
|
2475
|
+
options
|
|
2476
|
+
]);
|
|
2464
2477
|
}
|
|
2465
2478
|
});
|
|
2466
2479
|
api.modifyWebpackConfig(async (config) => {
|
|
@@ -2489,10 +2502,6 @@ __export(build_exports, {
|
|
|
2489
2502
|
build: () => build
|
|
2490
2503
|
});
|
|
2491
2504
|
import { logger as logger6 } from "@rsbuild/core";
|
|
2492
|
-
import {
|
|
2493
|
-
getNodeEnv as getNodeEnv2,
|
|
2494
|
-
setNodeEnv as setNodeEnv2
|
|
2495
|
-
} from "@rsbuild/shared";
|
|
2496
2505
|
import WebpackMultiStats2 from "webpack/lib/MultiStats.js";
|
|
2497
2506
|
var build;
|
|
2498
2507
|
var init_build = __esm({
|
|
@@ -2503,8 +2512,8 @@ var init_build = __esm({
|
|
|
2503
2512
|
init_initConfigs();
|
|
2504
2513
|
init_shared();
|
|
2505
2514
|
build = async (initOptions, { mode = "production", watch, compiler: customCompiler } = {}) => {
|
|
2506
|
-
if (!
|
|
2507
|
-
|
|
2515
|
+
if (!process.env.NODE_ENV) {
|
|
2516
|
+
process.env.NODE_ENV = mode;
|
|
2508
2517
|
}
|
|
2509
2518
|
const { context } = initOptions;
|
|
2510
2519
|
let compiler;
|
|
@@ -2521,10 +2530,15 @@ var init_build = __esm({
|
|
|
2521
2530
|
}
|
|
2522
2531
|
let isFirstCompile = true;
|
|
2523
2532
|
await context.hooks.onBeforeBuild.call({
|
|
2524
|
-
bundlerConfigs
|
|
2533
|
+
bundlerConfigs,
|
|
2534
|
+
environments: context.environments
|
|
2525
2535
|
});
|
|
2526
2536
|
const onDone = async (stats) => {
|
|
2527
|
-
const p = context.hooks.onAfterBuild.call({
|
|
2537
|
+
const p = context.hooks.onAfterBuild.call({
|
|
2538
|
+
isFirstCompile,
|
|
2539
|
+
stats,
|
|
2540
|
+
environments: context.environments
|
|
2541
|
+
});
|
|
2528
2542
|
isFirstCompile = false;
|
|
2529
2543
|
await p;
|
|
2530
2544
|
};
|
|
@@ -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.0",
|
|
4
4
|
"homepage": "https://rsbuild.dev",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -23,20 +23,20 @@
|
|
|
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
28
|
"tsconfig-paths-webpack-plugin": "4.1.0",
|
|
29
|
-
"webpack": "^5.92.
|
|
30
|
-
"@rsbuild/core": "0.
|
|
31
|
-
"@rsbuild/shared": "0.
|
|
29
|
+
"webpack": "^5.92.1",
|
|
30
|
+
"@rsbuild/core": "1.0.0-alpha.0",
|
|
31
|
+
"@rsbuild/shared": "1.0.0-alpha.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/node": "18.x",
|
|
35
35
|
"ansi-escapes": "4.3.2",
|
|
36
36
|
"cli-truncate": "2.1.0",
|
|
37
37
|
"patch-console": "1.0.0",
|
|
38
|
-
"typescript": "^5.
|
|
39
|
-
"@scripts/test-helper": "0.
|
|
38
|
+
"typescript": "^5.5.2",
|
|
39
|
+
"@scripts/test-helper": "1.0.0-alpha.0"
|
|
40
40
|
},
|
|
41
41
|
"publishConfig": {
|
|
42
42
|
"access": "public",
|