@rspack/cli 1.2.2 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -110,623 +110,623 @@ __webpack_require__.m = __webpack_modules__;
110
110
  };
111
111
  })();
112
112
  var __webpack_exports__ = {};
113
- __webpack_require__.r(__webpack_exports__);
114
- __webpack_require__.d(__webpack_exports__, {
115
- RspackCLI: ()=>RspackCLI,
116
- defineConfig: ()=>defineConfig,
117
- definePlugin: ()=>definePlugin
118
- });
119
- var external_node_path_ = __webpack_require__("node:path");
120
- var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_);
121
- const external_node_util_namespaceObject = require("node:util");
122
- var external_node_util_default = /*#__PURE__*/ __webpack_require__.n(external_node_util_namespaceObject);
123
- var core_ = __webpack_require__("@rspack/core");
124
- const external_colorette_namespaceObject = require("colorette");
125
- const external_yargs_namespaceObject = require("yargs");
126
- var external_yargs_default = /*#__PURE__*/ __webpack_require__.n(external_yargs_namespaceObject);
127
- const helpers_namespaceObject = require("yargs/helpers");
128
- var external_node_fs_ = __webpack_require__("node:fs");
129
- var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_);
130
- const commonOptions = (yargs)=>yargs.options({
131
- config: {
132
- g: true,
133
- type: "string",
134
- describe: "config file",
135
- alias: "c"
136
- },
137
- entry: {
138
- type: "array",
139
- string: true,
140
- describe: "entry file"
141
- },
142
- "output-path": {
143
- type: "string",
144
- describe: "output path dir",
145
- alias: "o"
146
- },
147
- mode: {
148
- type: "string",
149
- describe: "mode",
150
- alias: "m"
151
- },
152
- watch: {
153
- type: "boolean",
154
- default: false,
155
- describe: "watch",
156
- alias: "w"
157
- },
158
- env: {
159
- type: "array",
160
- string: true,
161
- describe: "env passed to config function"
162
- },
163
- "node-env": {
164
- string: true,
165
- describe: "sets process.env.NODE_ENV to be specified value"
166
- },
167
- devtool: {
168
- type: "boolean",
169
- default: false,
170
- describe: "devtool",
171
- alias: "d"
172
- },
173
- configName: {
174
- type: "array",
175
- string: true,
176
- describe: "Name of the configuration to use."
177
- }
178
- }).alias({
179
- v: "version",
180
- h: "help"
181
- });
182
- const previewOptions = (yargs)=>yargs.positional("dir", {
183
- type: "string",
184
- describe: "directory want to preview"
185
- }).options({
186
- publicPath: {
187
- type: "string",
188
- describe: "static resource server path"
189
- },
190
- config: {
191
- g: true,
192
- type: "string",
193
- describe: "config file",
194
- alias: "c"
195
- },
196
- port: {
197
- type: "number",
198
- describe: "preview server port"
199
- },
200
- host: {
201
- type: "string",
202
- describe: "preview server host"
203
- },
204
- open: {
205
- type: "boolean",
206
- describe: "open browser"
207
- },
208
- server: {
209
- type: "string",
210
- describe: "Configuration items for the server."
211
- },
212
- configName: {
213
- type: "array",
214
- string: true,
215
- describe: "Name of the configuration to use."
216
- }
113
+ (()=>{
114
+ __webpack_require__.r(__webpack_exports__);
115
+ __webpack_require__.d(__webpack_exports__, {
116
+ RspackCLI: ()=>RspackCLI,
117
+ defineConfig: ()=>defineConfig,
118
+ definePlugin: ()=>definePlugin
217
119
  });
218
- function normalizeEnv(argv) {
219
- function parseValue(previous, value) {
220
- const [allKeys, val] = value.split(/=(.+)/, 2);
221
- const splitKeys = allKeys.split(/\.(?!$)/);
222
- let prevRef = previous;
223
- splitKeys.forEach((key, index)=>{
224
- let someKey = key;
225
- if (someKey.endsWith("=")) {
226
- someKey = someKey.slice(0, -1);
227
- prevRef[someKey] = void 0;
228
- return;
120
+ var external_node_path_ = __webpack_require__("node:path");
121
+ var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_);
122
+ const external_node_util_namespaceObject = require("node:util");
123
+ var external_node_util_default = /*#__PURE__*/ __webpack_require__.n(external_node_util_namespaceObject);
124
+ var core_ = __webpack_require__("@rspack/core");
125
+ const external_colorette_namespaceObject = require("colorette");
126
+ const external_yargs_namespaceObject = require("yargs");
127
+ var external_yargs_default = /*#__PURE__*/ __webpack_require__.n(external_yargs_namespaceObject);
128
+ const helpers_namespaceObject = require("yargs/helpers");
129
+ var external_node_fs_ = __webpack_require__("node:fs");
130
+ var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_);
131
+ const commonOptions = (yargs)=>yargs.options({
132
+ config: {
133
+ g: true,
134
+ type: "string",
135
+ describe: "config file",
136
+ alias: "c"
137
+ },
138
+ entry: {
139
+ type: "array",
140
+ string: true,
141
+ describe: "entry file"
142
+ },
143
+ "output-path": {
144
+ type: "string",
145
+ describe: "output path dir",
146
+ alias: "o"
147
+ },
148
+ mode: {
149
+ type: "string",
150
+ describe: "mode",
151
+ alias: "m"
152
+ },
153
+ watch: {
154
+ type: "boolean",
155
+ default: false,
156
+ describe: "watch",
157
+ alias: "w"
158
+ },
159
+ env: {
160
+ type: "array",
161
+ string: true,
162
+ describe: "env passed to config function"
163
+ },
164
+ "node-env": {
165
+ string: true,
166
+ describe: "sets process.env.NODE_ENV to be specified value"
167
+ },
168
+ devtool: {
169
+ type: "boolean",
170
+ default: false,
171
+ describe: "devtool",
172
+ alias: "d"
173
+ },
174
+ configName: {
175
+ type: "array",
176
+ string: true,
177
+ describe: "Name of the configuration to use."
229
178
  }
230
- if (!prevRef[someKey] || "string" == typeof prevRef[someKey]) prevRef[someKey] = {};
231
- if (index === splitKeys.length - 1) {
232
- if ("string" == typeof val) prevRef[someKey] = val;
233
- else prevRef[someKey] = true;
179
+ }).alias({
180
+ v: "version",
181
+ h: "help"
182
+ });
183
+ const previewOptions = (yargs)=>yargs.positional("dir", {
184
+ type: "string",
185
+ describe: "directory want to preview"
186
+ }).options({
187
+ publicPath: {
188
+ type: "string",
189
+ describe: "static resource server path"
190
+ },
191
+ config: {
192
+ g: true,
193
+ type: "string",
194
+ describe: "config file",
195
+ alias: "c"
196
+ },
197
+ port: {
198
+ type: "number",
199
+ describe: "preview server port"
200
+ },
201
+ host: {
202
+ type: "string",
203
+ describe: "preview server host"
204
+ },
205
+ open: {
206
+ type: "boolean",
207
+ describe: "open browser"
208
+ },
209
+ server: {
210
+ type: "string",
211
+ describe: "Configuration items for the server."
212
+ },
213
+ configName: {
214
+ type: "array",
215
+ string: true,
216
+ describe: "Name of the configuration to use."
234
217
  }
235
- prevRef = prevRef[someKey];
236
218
  });
237
- return previous;
219
+ function normalizeEnv(argv) {
220
+ function parseValue(previous, value) {
221
+ const [allKeys, val] = value.split(/=(.+)/, 2);
222
+ const splitKeys = allKeys.split(/\.(?!$)/);
223
+ let prevRef = previous;
224
+ splitKeys.forEach((key, index)=>{
225
+ let someKey = key;
226
+ if (someKey.endsWith("=")) {
227
+ someKey = someKey.slice(0, -1);
228
+ prevRef[someKey] = void 0;
229
+ return;
230
+ }
231
+ if (!prevRef[someKey] || "string" == typeof prevRef[someKey]) prevRef[someKey] = {};
232
+ if (index === splitKeys.length - 1) {
233
+ if ("string" == typeof val) prevRef[someKey] = val;
234
+ else prevRef[someKey] = true;
235
+ }
236
+ prevRef = prevRef[someKey];
237
+ });
238
+ return previous;
239
+ }
240
+ const envObj = (argv.env ?? []).reduce(parseValue, {});
241
+ argv.env = envObj;
238
242
  }
239
- const envObj = (argv.env ?? []).reduce(parseValue, {});
240
- argv.env = envObj;
241
- }
242
- function setBuiltinEnvArg(env, envNameSuffix, value) {
243
- const envNames = [
244
- `RSPACK_${envNameSuffix}`
245
- ];
246
- for (const envName of envNames){
247
- if (!(envName in env)) env[envName] = value;
243
+ function setBuiltinEnvArg(env, envNameSuffix, value) {
244
+ const envNames = [
245
+ `RSPACK_${envNameSuffix}`
246
+ ];
247
+ for (const envName of envNames)if (!(envName in env)) env[envName] = value;
248
248
  }
249
- }
250
- function ensureEnvObject(options) {
251
- if (Array.isArray(options.env)) normalizeEnv(options);
252
- options.env = options.env || {};
253
- return options.env;
254
- }
255
- class BuildCommand {
256
- async apply(cli) {
257
- cli.program.command([
258
- "build",
259
- "$0",
260
- "bundle",
261
- "b"
262
- ], "run the rspack build", (yargs)=>commonOptions(yargs).options({
263
- analyze: {
264
- type: "boolean",
265
- default: false,
266
- describe: "analyze"
267
- },
268
- json: {
269
- describe: "emit stats json"
270
- },
271
- profile: {
272
- type: "boolean",
273
- default: false,
274
- describe: "capture timing information for each module"
249
+ function ensureEnvObject(options) {
250
+ if (Array.isArray(options.env)) normalizeEnv(options);
251
+ options.env = options.env || {};
252
+ return options.env;
253
+ }
254
+ class BuildCommand {
255
+ async apply(cli) {
256
+ cli.program.command([
257
+ "build",
258
+ "$0",
259
+ "bundle",
260
+ "b"
261
+ ], "run the rspack build", (yargs)=>commonOptions(yargs).options({
262
+ analyze: {
263
+ type: "boolean",
264
+ default: false,
265
+ describe: "analyze"
266
+ },
267
+ json: {
268
+ describe: "emit stats json"
269
+ },
270
+ profile: {
271
+ type: "boolean",
272
+ default: false,
273
+ describe: "capture timing information for each module"
274
+ }
275
+ }), async (options)=>{
276
+ const env = ensureEnvObject(options);
277
+ if (options.watch) setBuiltinEnvArg(env, "WATCH", true);
278
+ else {
279
+ setBuiltinEnvArg(env, "BUNDLE", true);
280
+ setBuiltinEnvArg(env, "BUILD", true);
275
281
  }
276
- }), async (options)=>{
277
- const env = ensureEnvObject(options);
278
- if (options.watch) setBuiltinEnvArg(env, "WATCH", true);
279
- else {
280
- setBuiltinEnvArg(env, "BUNDLE", true);
281
- setBuiltinEnvArg(env, "BUILD", true);
282
- }
283
- const logger = cli.getLogger();
284
- let createJsonStringifyStream;
285
- if (options.json) {
286
- const jsonExt = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "@discoveryjs/json-ext"));
287
- createJsonStringifyStream = jsonExt.default.stringifyStream;
288
- }
289
- const errorHandler = (error, stats)=>{
290
- if (error) {
291
- logger.error(error);
292
- process.exit(2);
282
+ const logger = cli.getLogger();
283
+ let createJsonStringifyStream;
284
+ if (options.json) {
285
+ const jsonExt = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "@discoveryjs/json-ext"));
286
+ createJsonStringifyStream = jsonExt.default.stringifyStream;
293
287
  }
294
- if (null == stats ? void 0 : stats.hasErrors()) process.exitCode = 1;
295
- if (!compiler || !stats) return;
296
- const statsOptions = cli.isMultipleCompiler(compiler) ? {
297
- children: compiler.compilers.map((compiler)=>compiler.options ? compiler.options.stats : void 0)
298
- } : compiler.options ? compiler.options.stats : void 0;
299
- if (options.json && createJsonStringifyStream) {
300
- const handleWriteError = (error)=>{
288
+ const errorHandler = (error, stats)=>{
289
+ if (error) {
301
290
  logger.error(error);
302
291
  process.exit(2);
303
- };
304
- if (true === options.json) createJsonStringifyStream(stats.toJson(statsOptions)).on("error", handleWriteError).pipe(process.stdout).on("error", handleWriteError).on("close", ()=>process.stdout.write("\n"));
305
- else if ("string" == typeof options.json) createJsonStringifyStream(stats.toJson(statsOptions)).on("error", handleWriteError).pipe(external_node_fs_.createWriteStream(options.json)).on("error", handleWriteError).on("close", ()=>{
306
- process.stderr.write(`[rspack-cli] ${cli.colors.green(`stats are successfully stored as json to ${options.json}`)}\n`);
292
+ }
293
+ if (null == stats ? void 0 : stats.hasErrors()) process.exitCode = 1;
294
+ if (!compiler || !stats) return;
295
+ const statsOptions = cli.isMultipleCompiler(compiler) ? {
296
+ children: compiler.compilers.map((compiler)=>compiler.options ? compiler.options.stats : void 0)
297
+ } : compiler.options ? compiler.options.stats : void 0;
298
+ if (options.json && createJsonStringifyStream) {
299
+ const handleWriteError = (error)=>{
300
+ logger.error(error);
301
+ process.exit(2);
302
+ };
303
+ if (true === options.json) createJsonStringifyStream(stats.toJson(statsOptions)).on("error", handleWriteError).pipe(process.stdout).on("error", handleWriteError).on("close", ()=>process.stdout.write("\n"));
304
+ else if ("string" == typeof options.json) createJsonStringifyStream(stats.toJson(statsOptions)).on("error", handleWriteError).pipe(external_node_fs_.createWriteStream(options.json)).on("error", handleWriteError).on("close", ()=>{
305
+ process.stderr.write(`[rspack-cli] ${cli.colors.green(`stats are successfully stored as json to ${options.json}`)}\n`);
306
+ });
307
+ } else {
308
+ const printedStats = stats.toString(statsOptions);
309
+ if (printedStats) logger.raw(printedStats);
310
+ }
311
+ };
312
+ const rspackOptions = {
313
+ ...options,
314
+ argv: {
315
+ ...options
316
+ }
317
+ };
318
+ const compiler = await cli.createCompiler(rspackOptions, "build", errorHandler);
319
+ if (!compiler || cli.isWatch(compiler)) return;
320
+ compiler.run((error, stats)=>{
321
+ if (error || (null == stats ? void 0 : stats.hasErrors())) errorHandler(error, stats);
322
+ else compiler.close((closeErr)=>{
323
+ if (closeErr) logger.error(closeErr);
324
+ errorHandler(error, stats);
307
325
  });
308
- } else {
309
- const printedStats = stats.toString(statsOptions);
310
- if (printedStats) logger.raw(printedStats);
311
- }
312
- };
313
- const rspackOptions = {
314
- ...options,
315
- argv: {
316
- ...options
317
- }
318
- };
319
- const compiler = await cli.createCompiler(rspackOptions, "build", errorHandler);
320
- if (!compiler || cli.isWatch(compiler)) return;
321
- compiler.run((error, stats)=>{
322
- if (error || (null == stats ? void 0 : stats.hasErrors())) errorHandler(error, stats);
323
- else compiler.close((closeErr)=>{
324
- if (closeErr) logger.error(closeErr);
325
- errorHandler(error, stats);
326
326
  });
327
327
  });
328
- });
328
+ }
329
329
  }
330
- }
331
- const defaultRoot = "dist";
332
- class PreviewCommand {
333
- async apply(cli) {
334
- cli.program.command([
335
- "preview [dir]",
336
- "preview",
337
- "p"
338
- ], "run the rspack server for build output", previewOptions, async (options)=>{
339
- const rspackOptions = {
340
- config: options.config,
341
- configName: options.configName,
342
- argv: {
343
- ...options
330
+ const defaultRoot = "dist";
331
+ class PreviewCommand {
332
+ async apply(cli) {
333
+ cli.program.command([
334
+ "preview [dir]",
335
+ "preview",
336
+ "p"
337
+ ], "run the rspack server for build output", previewOptions, async (options)=>{
338
+ const rspackOptions = {
339
+ config: options.config,
340
+ configName: options.configName,
341
+ argv: {
342
+ ...options
343
+ }
344
+ };
345
+ const { RspackDevServer } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "@rspack/dev-server"));
346
+ let config = await cli.loadConfig(rspackOptions);
347
+ config = await getPreviewConfig(config, options);
348
+ if (!Array.isArray(config)) config = [
349
+ config
350
+ ];
351
+ config = config.find((item)=>item.devServer) || config[0];
352
+ const devServerOptions = config.devServer;
353
+ try {
354
+ const compiler = (0, core_.rspack)({
355
+ entry: {}
356
+ });
357
+ if (!compiler) return;
358
+ const server = new RspackDevServer(devServerOptions, compiler);
359
+ await server.start();
360
+ } catch (error) {
361
+ const logger = cli.getLogger();
362
+ logger.error(error);
363
+ process.exit(2);
344
364
  }
345
- };
346
- const { RspackDevServer } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "@rspack/dev-server"));
347
- let config = await cli.loadConfig(rspackOptions);
348
- config = await getPreviewConfig(config, options);
349
- if (!Array.isArray(config)) config = [
350
- config
351
- ];
352
- config = config.find((item)=>item.devServer) || config[0];
353
- const devServerOptions = config.devServer;
354
- try {
355
- const compiler = (0, core_.rspack)({
356
- entry: {}
357
- });
358
- if (!compiler) return;
359
- const server = new RspackDevServer(devServerOptions, compiler);
360
- await server.start();
361
- } catch (error) {
362
- const logger = cli.getLogger();
363
- logger.error(error);
364
- process.exit(2);
365
- }
366
- });
365
+ });
366
+ }
367
367
  }
368
- }
369
- async function getPreviewConfig(item, options) {
370
- const internalPreviewConfig = async (item)=>{
371
- var _item_output, _item_devServer, _item_devServer1, _item_devServer2, _item_devServer3, _item_devServer4;
372
- item.devServer = {
373
- static: {
374
- directory: options.dir ? external_node_path_default().join(item.context ?? process.cwd(), options.dir) : (null === (_item_output = item.output) || void 0 === _item_output ? void 0 : _item_output.path) ?? external_node_path_default().join(item.context ?? process.cwd(), defaultRoot),
375
- publicPath: options.publicPath ?? "/"
376
- },
377
- port: options.port ?? 8080,
378
- proxy: null === (_item_devServer = item.devServer) || void 0 === _item_devServer ? void 0 : _item_devServer.proxy,
379
- host: options.host ?? (null === (_item_devServer1 = item.devServer) || void 0 === _item_devServer1 ? void 0 : _item_devServer1.host),
380
- open: options.open ?? (null === (_item_devServer2 = item.devServer) || void 0 === _item_devServer2 ? void 0 : _item_devServer2.open),
381
- server: options.server ?? (null === (_item_devServer3 = item.devServer) || void 0 === _item_devServer3 ? void 0 : _item_devServer3.server),
382
- historyApiFallback: null === (_item_devServer4 = item.devServer) || void 0 === _item_devServer4 ? void 0 : _item_devServer4.historyApiFallback
368
+ async function getPreviewConfig(item, options) {
369
+ const internalPreviewConfig = async (item)=>{
370
+ var _item_output, _item_devServer, _item_devServer1, _item_devServer2, _item_devServer3, _item_devServer4;
371
+ item.devServer = {
372
+ static: {
373
+ directory: options.dir ? external_node_path_default().join(item.context ?? process.cwd(), options.dir) : (null === (_item_output = item.output) || void 0 === _item_output ? void 0 : _item_output.path) ?? external_node_path_default().join(item.context ?? process.cwd(), defaultRoot),
374
+ publicPath: options.publicPath ?? "/"
375
+ },
376
+ port: options.port ?? 8080,
377
+ proxy: null === (_item_devServer = item.devServer) || void 0 === _item_devServer ? void 0 : _item_devServer.proxy,
378
+ host: options.host ?? (null === (_item_devServer1 = item.devServer) || void 0 === _item_devServer1 ? void 0 : _item_devServer1.host),
379
+ open: options.open ?? (null === (_item_devServer2 = item.devServer) || void 0 === _item_devServer2 ? void 0 : _item_devServer2.open),
380
+ server: options.server ?? (null === (_item_devServer3 = item.devServer) || void 0 === _item_devServer3 ? void 0 : _item_devServer3.server),
381
+ historyApiFallback: null === (_item_devServer4 = item.devServer) || void 0 === _item_devServer4 ? void 0 : _item_devServer4.historyApiFallback
382
+ };
383
+ return item;
383
384
  };
384
- return item;
385
- };
386
- if (Array.isArray(item)) return Promise.all(item.map(internalPreviewConfig));
387
- return internalPreviewConfig(item);
388
- }
389
- class ServeCommand {
390
- async apply(cli) {
391
- cli.program.command([
392
- "serve",
393
- "server",
394
- "s",
395
- "dev"
396
- ], "run the rspack dev server.", (yargs)=>commonOptions(yargs).options({
397
- hot: {
398
- coerce: (arg)=>{
399
- if ("boolean" == typeof arg || "only" === arg) return arg;
400
- if ("false" === arg) return false;
401
- return true;
385
+ if (Array.isArray(item)) return Promise.all(item.map(internalPreviewConfig));
386
+ return internalPreviewConfig(item);
387
+ }
388
+ class ServeCommand {
389
+ async apply(cli) {
390
+ cli.program.command([
391
+ "serve",
392
+ "server",
393
+ "s",
394
+ "dev"
395
+ ], "run the rspack dev server.", (yargs)=>commonOptions(yargs).options({
396
+ hot: {
397
+ coerce: (arg)=>{
398
+ if ("boolean" == typeof arg || "only" === arg) return arg;
399
+ if ("false" === arg) return false;
400
+ return true;
401
+ },
402
+ describe: "enables hot module replacement"
402
403
  },
403
- describe: "enables hot module replacement"
404
- },
405
- port: {
406
- type: "number",
407
- coerce: (arg)=>Number.isInteger(arg) ? arg : void 0,
408
- describe: "allows to specify a port to use"
409
- },
410
- host: {
411
- type: "string",
412
- describe: "allows to specify a hostname to use"
413
- }
414
- }), async (options)=>{
415
- setBuiltinEnvArg(ensureEnvObject(options), "SERVE", true);
416
- const rspackOptions = {
417
- ...options,
418
- argv: {
419
- ...options
404
+ port: {
405
+ type: "number",
406
+ coerce: (arg)=>Number.isInteger(arg) ? arg : void 0,
407
+ describe: "allows to specify a port to use"
408
+ },
409
+ host: {
410
+ type: "string",
411
+ describe: "allows to specify a hostname to use"
412
+ }
413
+ }), async (options)=>{
414
+ setBuiltinEnvArg(ensureEnvObject(options), "SERVE", true);
415
+ const rspackOptions = {
416
+ ...options,
417
+ argv: {
418
+ ...options
419
+ }
420
+ };
421
+ const { RspackDevServer } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "@rspack/dev-server"));
422
+ const compiler = await cli.createCompiler(rspackOptions, "serve");
423
+ if (!compiler) return;
424
+ const compilers = cli.isMultipleCompiler(compiler) ? compiler.compilers : [
425
+ compiler
426
+ ];
427
+ const possibleCompilers = compilers.filter((compiler)=>compiler.options.devServer);
428
+ const usedPorts = [];
429
+ const servers = [];
430
+ const compilerForDevServer = possibleCompilers.length > 0 ? possibleCompilers[0] : compilers[0];
431
+ for (const compiler of compilers){
432
+ const devServer = compiler.options.devServer ??= {};
433
+ devServer.hot = options.hot ?? devServer.hot ?? true;
434
+ if (false !== devServer.client) {
435
+ if (true === devServer.client || null == devServer.client) devServer.client = {};
436
+ devServer.client = {
437
+ overlay: {
438
+ errors: true,
439
+ warnings: false
440
+ },
441
+ ...devServer.client
442
+ };
443
+ }
420
444
  }
421
- };
422
- const { RspackDevServer } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "@rspack/dev-server"));
423
- const compiler = await cli.createCompiler(rspackOptions, "serve");
424
- if (!compiler) return;
425
- const compilers = cli.isMultipleCompiler(compiler) ? compiler.compilers : [
426
- compiler
427
- ];
428
- const possibleCompilers = compilers.filter((compiler)=>compiler.options.devServer);
429
- const usedPorts = [];
430
- const servers = [];
431
- const compilerForDevServer = possibleCompilers.length > 0 ? possibleCompilers[0] : compilers[0];
432
- for (const compiler of compilers){
433
- const devServer = compiler.options.devServer ??= {};
434
- devServer.hot = options.hot ?? devServer.hot ?? true;
435
- if (false !== devServer.client) {
436
- if (true === devServer.client || null == devServer.client) devServer.client = {};
437
- devServer.client = {
445
+ const result = compilerForDevServer.options.devServer ??= {};
446
+ result.hot = options.hot ?? result.hot ?? true;
447
+ result.host = options.host || result.host;
448
+ result.port = options.port || result.port;
449
+ if (false !== result.client) {
450
+ if (true === result.client || null == result.client) result.client = {};
451
+ result.client = {
438
452
  overlay: {
439
453
  errors: true,
440
454
  warnings: false
441
455
  },
442
- ...devServer.client
456
+ ...result.client
443
457
  };
444
458
  }
445
- }
446
- const result = compilerForDevServer.options.devServer ??= {};
447
- result.hot = options.hot ?? result.hot ?? true;
448
- result.host = options.host || result.host;
449
- result.port = options.port || result.port;
450
- if (false !== result.client) {
451
- if (true === result.client || null == result.client) result.client = {};
452
- result.client = {
453
- overlay: {
454
- errors: true,
455
- warnings: false
456
- },
457
- ...result.client
458
- };
459
- }
460
- const devServerOptions = result;
461
- if (devServerOptions.port) {
462
- const portNumber = Number(devServerOptions.port);
463
- if (!Number.isNaN(portNumber)) {
464
- if (usedPorts.find((port)=>portNumber === port)) throw new Error("Unique ports must be specified for each devServer option in your rspack configuration. Alternatively, run only 1 devServer config using the --config-name flag to specify your desired config.");
465
- usedPorts.push(portNumber);
459
+ const devServerOptions = result;
460
+ if (devServerOptions.port) {
461
+ const portNumber = Number(devServerOptions.port);
462
+ if (!Number.isNaN(portNumber)) {
463
+ if (usedPorts.find((port)=>portNumber === port)) throw new Error("Unique ports must be specified for each devServer option in your rspack configuration. Alternatively, run only 1 devServer config using the --config-name flag to specify your desired config.");
464
+ usedPorts.push(portNumber);
465
+ }
466
466
  }
467
- }
468
- try {
469
- const server = new RspackDevServer(devServerOptions, compiler);
470
- await server.start();
471
- servers.push(server);
472
- } catch (error) {
473
- const logger = cli.getLogger();
474
- logger.error(error);
475
- process.exit(2);
476
- }
477
- });
478
- }
479
- }
480
- var external_node_url_ = __webpack_require__("node:url");
481
- const readPackageUp = (cwd = process.cwd())=>{
482
- let currentDir = external_node_path_default().resolve(cwd);
483
- let packageJsonPath = external_node_path_default().join(currentDir, "package.json");
484
- while(!external_node_fs_default().existsSync(packageJsonPath)){
485
- const parentDir = external_node_path_default().dirname(currentDir);
486
- if (parentDir === currentDir) return null;
487
- currentDir = parentDir;
488
- packageJsonPath = external_node_path_default().join(currentDir, "package.json");
489
- }
490
- try {
491
- return JSON.parse(external_node_fs_default().readFileSync(packageJsonPath, "utf8"));
492
- } catch (error) {
493
- return null;
494
- }
495
- };
496
- const utils_readPackageUp = readPackageUp;
497
- const isEsmFile = (filePath, cwd = process.cwd())=>{
498
- const ext = external_node_path_default().extname(filePath);
499
- if (/\.(mjs|mts)$/.test(ext)) return true;
500
- if (/\.(cjs|cts)/.test(ext)) return false;
501
- const packageJson = utils_readPackageUp(external_node_path_default().dirname(filePath));
502
- return (null == packageJson ? void 0 : packageJson.type) === "module";
503
- };
504
- const utils_isEsmFile = isEsmFile;
505
- const crossImport = async (path, cwd = process.cwd())=>{
506
- if (utils_isEsmFile(path, cwd)) {
507
- const url = (0, external_node_url_.pathToFileURL)(path).href;
508
- const { default: config } = await import(url);
509
- return config;
510
- }
511
- let result = require(path);
512
- if (result && "object" == typeof result && "default" in result) result = result.default || {};
513
- return result;
514
- };
515
- const DEFAULT_EXTENSIONS = [
516
- ".js",
517
- ".ts",
518
- ".mjs",
519
- ".mts",
520
- ".cjs",
521
- ".cts"
522
- ];
523
- const findConfig = (basePath)=>DEFAULT_EXTENSIONS.map((ext)=>basePath + ext).find(external_node_fs_default().existsSync);
524
- const utils_findConfig = findConfig;
525
- const isTsFile_isTsFile = (configPath)=>{
526
- const ext = external_node_path_default().extname(configPath);
527
- return /\.(c|m)?ts$/.test(ext);
528
- };
529
- const isTsFile = isTsFile_isTsFile;
530
- const loadConfig_DEFAULT_CONFIG_NAME = "rspack.config";
531
- const registerLoader = async (configPath)=>{
532
- const ext = external_node_path_default().extname(configPath);
533
- if (utils_isEsmFile(configPath) && isTsFile(configPath)) return;
534
- const { default: interpret } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "interpret"));
535
- const extensions = Object.fromEntries(Object.entries(interpret.extensions).filter(([key])=>key === ext));
536
- if (0 === Object.keys(extensions).length) throw new Error(`config file "${configPath}" is not supported.`);
537
- try {
538
- const { default: rechoir } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "rechoir"));
539
- rechoir.prepare(extensions, configPath);
540
- } catch (error) {
541
- const failures = null == error ? void 0 : error.failures;
542
- if (failures) {
543
- const messages = failures.map((failure)=>failure.error.message);
544
- throw new Error(`${messages.join("\n")}`);
467
+ try {
468
+ const server = new RspackDevServer(devServerOptions, compiler);
469
+ await server.start();
470
+ servers.push(server);
471
+ } catch (error) {
472
+ const logger = cli.getLogger();
473
+ logger.error(error);
474
+ process.exit(2);
475
+ }
476
+ });
545
477
  }
546
- throw error;
547
- }
548
- };
549
- async function loadRspackConfig(options, cwd = process.cwd()) {
550
- if (options.config) {
551
- const configPath = external_node_path_default().resolve(cwd, options.config);
552
- if (!external_node_fs_default().existsSync(configPath)) throw new Error(`config file "${configPath}" not found.`);
553
- if (isTsFile(configPath)) await registerLoader(configPath);
554
- return crossImport(configPath, cwd);
555
478
  }
556
- const defaultConfig = utils_findConfig(external_node_path_default().resolve(cwd, loadConfig_DEFAULT_CONFIG_NAME));
557
- if (defaultConfig) {
558
- if (isTsFile(defaultConfig)) await registerLoader(defaultConfig);
559
- return crossImport(defaultConfig, cwd);
560
- }
561
- return {};
562
- }
563
- function _define_property(obj, key, value) {
564
- if (key in obj) Object.defineProperty(obj, key, {
565
- value: value,
566
- enumerable: true,
567
- configurable: true,
568
- writable: true
569
- });
570
- else obj[key] = value;
571
- return obj;
572
- }
573
- class RspackCLI {
574
- async createCompiler(options, rspackCommand, callback) {
575
- var _process_env, _process;
576
- process.env.RSPACK_CONFIG_VALIDATE ??= "loose";
577
- process.env.WATCHPACK_WATCHER_LIMIT = process.env.WATCHPACK_WATCHER_LIMIT || "20";
578
- const nodeEnv = null === (_process = process) || void 0 === _process ? void 0 : null === (_process_env = _process.env) || void 0 === _process_env ? void 0 : _process_env.NODE_ENV;
579
- const rspackCommandDefaultEnv = "build" === rspackCommand ? "production" : "development";
580
- if ("string" == typeof options.nodeEnv) process.env.NODE_ENV = nodeEnv || options.nodeEnv;
581
- else process.env.NODE_ENV = nodeEnv || rspackCommandDefaultEnv;
582
- let config = await this.loadConfig(options);
583
- config = await this.buildConfig(config, options, rspackCommand);
584
- const isWatch = Array.isArray(config) ? config.some((i)=>i.watch) : config.watch;
585
- let compiler;
479
+ var external_node_url_ = __webpack_require__("node:url");
480
+ const readPackageUp = (cwd = process.cwd())=>{
481
+ let currentDir = external_node_path_default().resolve(cwd);
482
+ let packageJsonPath = external_node_path_default().join(currentDir, "package.json");
483
+ while(!external_node_fs_default().existsSync(packageJsonPath)){
484
+ const parentDir = external_node_path_default().dirname(currentDir);
485
+ if (parentDir === currentDir) return null;
486
+ currentDir = parentDir;
487
+ packageJsonPath = external_node_path_default().join(currentDir, "package.json");
488
+ }
586
489
  try {
587
- compiler = (0, core_.rspack)(config, isWatch ? callback : void 0);
588
- } catch (e) {
589
- if (e instanceof core_.ValidationError) {
590
- this.getLogger().error(e.message);
591
- process.exit(2);
592
- } else if (e instanceof Error) {
593
- if ("function" == typeof callback) callback(e);
594
- else this.getLogger().error(e);
595
- return null;
490
+ return JSON.parse(external_node_fs_default().readFileSync(packageJsonPath, "utf8"));
491
+ } catch (error) {
492
+ return null;
493
+ }
494
+ };
495
+ const utils_readPackageUp = readPackageUp;
496
+ const isEsmFile = (filePath, cwd = process.cwd())=>{
497
+ const ext = external_node_path_default().extname(filePath);
498
+ if (/\.(mjs|mts)$/.test(ext)) return true;
499
+ if (/\.(cjs|cts)/.test(ext)) return false;
500
+ const packageJson = utils_readPackageUp(external_node_path_default().dirname(filePath));
501
+ return (null == packageJson ? void 0 : packageJson.type) === "module";
502
+ };
503
+ const utils_isEsmFile = isEsmFile;
504
+ const crossImport = async (path, cwd = process.cwd())=>{
505
+ if (utils_isEsmFile(path, cwd)) {
506
+ const url = (0, external_node_url_.pathToFileURL)(path).href;
507
+ const { default: config } = await import(url);
508
+ return config;
509
+ }
510
+ let result = require(path);
511
+ if (result && "object" == typeof result && "default" in result) result = result.default || {};
512
+ return result;
513
+ };
514
+ const DEFAULT_EXTENSIONS = [
515
+ ".js",
516
+ ".ts",
517
+ ".mjs",
518
+ ".mts",
519
+ ".cjs",
520
+ ".cts"
521
+ ];
522
+ const findConfig = (basePath)=>DEFAULT_EXTENSIONS.map((ext)=>basePath + ext).find(external_node_fs_default().existsSync);
523
+ const utils_findConfig = findConfig;
524
+ const isTsFile_isTsFile = (configPath)=>{
525
+ const ext = external_node_path_default().extname(configPath);
526
+ return /\.(c|m)?ts$/.test(ext);
527
+ };
528
+ const isTsFile = isTsFile_isTsFile;
529
+ const loadConfig_DEFAULT_CONFIG_NAME = "rspack.config";
530
+ const registerLoader = async (configPath)=>{
531
+ const ext = external_node_path_default().extname(configPath);
532
+ if (utils_isEsmFile(configPath) && isTsFile(configPath)) return;
533
+ const { default: interpret } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "interpret"));
534
+ const extensions = Object.fromEntries(Object.entries(interpret.extensions).filter(([key])=>key === ext));
535
+ if (0 === Object.keys(extensions).length) throw new Error(`config file "${configPath}" is not supported.`);
536
+ try {
537
+ const { default: rechoir } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "rechoir"));
538
+ rechoir.prepare(extensions, configPath);
539
+ } catch (error) {
540
+ const failures = null == error ? void 0 : error.failures;
541
+ if (failures) {
542
+ const messages = failures.map((failure)=>failure.error.message);
543
+ throw new Error(`${messages.join("\n")}`);
596
544
  }
597
- throw e;
545
+ throw error;
598
546
  }
599
- return compiler;
600
- }
601
- createColors(useColor) {
602
- const shouldUseColor = useColor || external_colorette_namespaceObject.isColorSupported;
603
- return {
604
- ...(0, external_colorette_namespaceObject.createColors)({
605
- useColor: shouldUseColor
606
- }),
607
- isColorSupported: shouldUseColor
608
- };
609
- }
610
- getLogger() {
611
- return {
612
- error: (val)=>console.error(`[rspack-cli] ${this.colors.red(external_node_util_default().format(val))}`),
613
- warn: (val)=>console.warn(`[rspack-cli] ${this.colors.yellow(val)}`),
614
- info: (val)=>console.info(`[rspack-cli] ${this.colors.cyan(val)}`),
615
- success: (val)=>console.log(`[rspack-cli] ${this.colors.green(val)}`),
616
- log: (val)=>console.log(`[rspack-cli] ${val}`),
617
- raw: (val)=>console.log(val)
618
- };
619
- }
620
- async run(argv) {
621
- this.program.showHelpOnFail(false);
622
- this.program.usage("[options]");
623
- this.program.scriptName("rspack");
624
- this.program.strictCommands(true).strict(true);
625
- this.program.middleware(normalizeEnv);
626
- this.registerCommands();
627
- await this.program.parseAsync((0, helpers_namespaceObject.hideBin)(argv));
547
+ };
548
+ async function loadRspackConfig(options, cwd = process.cwd()) {
549
+ if (options.config) {
550
+ const configPath = external_node_path_default().resolve(cwd, options.config);
551
+ if (!external_node_fs_default().existsSync(configPath)) throw new Error(`config file "${configPath}" not found.`);
552
+ if (isTsFile(configPath)) await registerLoader(configPath);
553
+ return crossImport(configPath, cwd);
554
+ }
555
+ const defaultConfig = utils_findConfig(external_node_path_default().resolve(cwd, loadConfig_DEFAULT_CONFIG_NAME));
556
+ if (defaultConfig) {
557
+ if (isTsFile(defaultConfig)) await registerLoader(defaultConfig);
558
+ return crossImport(defaultConfig, cwd);
559
+ }
560
+ return {};
628
561
  }
629
- async registerCommands() {
630
- const builtinCommands = [
631
- new BuildCommand(),
632
- new ServeCommand(),
633
- new PreviewCommand()
634
- ];
635
- for (const command of builtinCommands)command.apply(this);
562
+ function _define_property(obj, key, value) {
563
+ if (key in obj) Object.defineProperty(obj, key, {
564
+ value: value,
565
+ enumerable: true,
566
+ configurable: true,
567
+ writable: true
568
+ });
569
+ else obj[key] = value;
570
+ return obj;
636
571
  }
637
- async buildConfig(item, options, command) {
638
- const isBuild = "build" === command;
639
- const isServe = "serve" === command;
640
- const commandDefaultEnv = isBuild ? "production" : "development";
641
- const internalBuildConfig = async (item)=>{
642
- if (options.entry) item.entry = {
643
- main: options.entry.map((x)=>external_node_path_default().resolve(process.cwd(), x))[0]
644
- };
645
- item.output = item.output || {};
646
- if (options["output-path"]) item.output.path = external_node_path_default().resolve(process.cwd(), options["output-path"]);
647
- if (options.analyze) {
648
- const { BundleAnalyzerPlugin } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "webpack-bundle-analyzer"));
649
- (item.plugins ??= []).push({
650
- name: "rspack-bundle-analyzer",
651
- apply (compiler) {
652
- new BundleAnalyzerPlugin({
653
- generateStatsFile: true
654
- }).apply(compiler);
655
- }
656
- });
657
- }
658
- if (options.profile) item.profile = true;
659
- if (process.env.RSPACK_PROFILE) {
660
- const { applyProfile } = await __webpack_require__.e("574").then(__webpack_require__.bind(__webpack_require__, "./src/utils/profile.ts"));
661
- await applyProfile(process.env.RSPACK_PROFILE, item);
662
- }
663
- if (options.watch) item.watch = options.watch;
664
- if (!item.mode) item.mode = commandDefaultEnv ?? "none";
665
- if (options.mode) item.mode = options.mode;
666
- if (void 0 === item.devtool) item.devtool = isBuild ? "source-map" : "cheap-module-source-map";
667
- if (isServe) {
668
- const installed = (item.plugins ||= []).find((item)=>item instanceof core_.ProgressPlugin);
669
- if (!installed) (item.plugins ??= []).push(new core_.ProgressPlugin());
572
+ class RspackCLI {
573
+ async createCompiler(options, rspackCommand, callback) {
574
+ var _process_env, _process;
575
+ process.env.RSPACK_CONFIG_VALIDATE ??= "loose";
576
+ process.env.WATCHPACK_WATCHER_LIMIT = process.env.WATCHPACK_WATCHER_LIMIT || "20";
577
+ const nodeEnv = null === (_process = process) || void 0 === _process ? void 0 : null === (_process_env = _process.env) || void 0 === _process_env ? void 0 : _process_env.NODE_ENV;
578
+ const rspackCommandDefaultEnv = "build" === rspackCommand ? "production" : "development";
579
+ if ("string" == typeof options.nodeEnv) process.env.NODE_ENV = nodeEnv || options.nodeEnv;
580
+ else process.env.NODE_ENV = nodeEnv || rspackCommandDefaultEnv;
581
+ let config = await this.loadConfig(options);
582
+ config = await this.buildConfig(config, options, rspackCommand);
583
+ const isWatch = Array.isArray(config) ? config.some((i)=>i.watch) : config.watch;
584
+ let compiler;
585
+ try {
586
+ compiler = (0, core_.rspack)(config, isWatch ? callback : void 0);
587
+ } catch (e) {
588
+ if (e instanceof core_.ValidationError) {
589
+ this.getLogger().error(e.message);
590
+ process.exit(2);
591
+ } else if (e instanceof Error) {
592
+ if ("function" == typeof callback) callback(e);
593
+ else this.getLogger().error(e);
594
+ return null;
595
+ }
596
+ throw e;
670
597
  }
671
- if (void 0 === item.stats) item.stats = {
672
- preset: "errors-warnings",
673
- timings: true
598
+ return compiler;
599
+ }
600
+ createColors(useColor) {
601
+ const shouldUseColor = useColor || external_colorette_namespaceObject.isColorSupported;
602
+ return {
603
+ ...(0, external_colorette_namespaceObject.createColors)({
604
+ useColor: shouldUseColor
605
+ }),
606
+ isColorSupported: shouldUseColor
674
607
  };
675
- else if ("boolean" == typeof item.stats) item.stats = item.stats ? {
676
- preset: "normal"
677
- } : {
678
- preset: "none"
608
+ }
609
+ getLogger() {
610
+ return {
611
+ error: (val)=>console.error(`[rspack-cli] ${this.colors.red(external_node_util_default().format(val))}`),
612
+ warn: (val)=>console.warn(`[rspack-cli] ${this.colors.yellow(val)}`),
613
+ info: (val)=>console.info(`[rspack-cli] ${this.colors.cyan(val)}`),
614
+ success: (val)=>console.log(`[rspack-cli] ${this.colors.green(val)}`),
615
+ log: (val)=>console.log(`[rspack-cli] ${val}`),
616
+ raw: (val)=>console.log(val)
679
617
  };
680
- else if ("string" == typeof item.stats) item.stats = {
681
- preset: item.stats
618
+ }
619
+ async run(argv) {
620
+ this.program.showHelpOnFail(false);
621
+ this.program.usage("[options]");
622
+ this.program.scriptName("rspack");
623
+ this.program.strictCommands(true).strict(true);
624
+ this.program.middleware(normalizeEnv);
625
+ this.registerCommands();
626
+ await this.program.parseAsync((0, helpers_namespaceObject.hideBin)(argv));
627
+ }
628
+ async registerCommands() {
629
+ const builtinCommands = [
630
+ new BuildCommand(),
631
+ new ServeCommand(),
632
+ new PreviewCommand()
633
+ ];
634
+ for (const command of builtinCommands)command.apply(this);
635
+ }
636
+ async buildConfig(item, options, command) {
637
+ const isBuild = "build" === command;
638
+ const isServe = "serve" === command;
639
+ const commandDefaultEnv = isBuild ? "production" : "development";
640
+ const internalBuildConfig = async (item)=>{
641
+ if (options.entry) item.entry = {
642
+ main: options.entry.map((x)=>external_node_path_default().resolve(process.cwd(), x))[0]
643
+ };
644
+ item.output = item.output || {};
645
+ if (options["output-path"]) item.output.path = external_node_path_default().resolve(process.cwd(), options["output-path"]);
646
+ if (options.analyze) {
647
+ const { BundleAnalyzerPlugin } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "webpack-bundle-analyzer"));
648
+ (item.plugins ??= []).push({
649
+ name: "rspack-bundle-analyzer",
650
+ apply (compiler) {
651
+ new BundleAnalyzerPlugin({
652
+ generateStatsFile: true
653
+ }).apply(compiler);
654
+ }
655
+ });
656
+ }
657
+ if (options.profile) item.profile = true;
658
+ if (process.env.RSPACK_PROFILE) {
659
+ const { applyProfile } = await __webpack_require__.e("737").then(__webpack_require__.bind(__webpack_require__, "./src/utils/profile.ts"));
660
+ await applyProfile(process.env.RSPACK_PROFILE, item);
661
+ }
662
+ if (options.watch) item.watch = options.watch;
663
+ if (!item.mode) item.mode = commandDefaultEnv ?? "none";
664
+ if (options.mode) item.mode = options.mode;
665
+ if (void 0 === item.devtool) item.devtool = isBuild ? "source-map" : "cheap-module-source-map";
666
+ if (isServe) {
667
+ const installed = (item.plugins ||= []).find((item)=>item instanceof core_.ProgressPlugin);
668
+ if (!installed) (item.plugins ??= []).push(new core_.ProgressPlugin());
669
+ }
670
+ if (void 0 === item.stats) item.stats = {
671
+ preset: "errors-warnings",
672
+ timings: true
673
+ };
674
+ else if ("boolean" == typeof item.stats) item.stats = item.stats ? {
675
+ preset: "normal"
676
+ } : {
677
+ preset: "none"
678
+ };
679
+ else if ("string" == typeof item.stats) item.stats = {
680
+ preset: item.stats
681
+ };
682
+ if (this.colors.isColorSupported && void 0 === item.stats.colors) item.stats.colors = true;
683
+ return item;
682
684
  };
683
- if (this.colors.isColorSupported && void 0 === item.stats.colors) item.stats.colors = true;
684
- return item;
685
- };
686
- if (Array.isArray(item)) return Promise.all(item.map(internalBuildConfig));
687
- return internalBuildConfig(item);
688
- }
689
- async loadConfig(options) {
690
- let loadedConfig = await loadRspackConfig(options);
691
- if ("function" == typeof loadedConfig) {
692
- var _options_argv;
693
- loadedConfig = loadedConfig(null === (_options_argv = options.argv) || void 0 === _options_argv ? void 0 : _options_argv.env, options.argv);
694
- if ("function" == typeof loadedConfig.then) loadedConfig = await loadedConfig;
685
+ if (Array.isArray(item)) return Promise.all(item.map(internalBuildConfig));
686
+ return internalBuildConfig(item);
695
687
  }
696
- if (options.configName) {
697
- const notFoundConfigNames = [];
698
- loadedConfig = options.configName.map((configName)=>{
699
- let found;
700
- found = Array.isArray(loadedConfig) ? loadedConfig.find((options)=>options.name === configName) : loadedConfig.name === configName ? loadedConfig : void 0;
701
- if (!found) notFoundConfigNames.push(configName);
702
- return found;
703
- });
704
- if (notFoundConfigNames.length > 0) {
705
- this.getLogger().error(notFoundConfigNames.map((configName)=>`Configuration with the name "${configName}" was not found.`).join(" "));
706
- process.exit(2);
688
+ async loadConfig(options) {
689
+ let loadedConfig = await loadRspackConfig(options);
690
+ if ("function" == typeof loadedConfig) {
691
+ var _options_argv;
692
+ loadedConfig = loadedConfig(null === (_options_argv = options.argv) || void 0 === _options_argv ? void 0 : _options_argv.env, options.argv);
693
+ if ("function" == typeof loadedConfig.then) loadedConfig = await loadedConfig;
707
694
  }
695
+ if (options.configName) {
696
+ const notFoundConfigNames = [];
697
+ loadedConfig = options.configName.map((configName)=>{
698
+ let found;
699
+ found = Array.isArray(loadedConfig) ? loadedConfig.find((options)=>options.name === configName) : loadedConfig.name === configName ? loadedConfig : void 0;
700
+ if (!found) notFoundConfigNames.push(configName);
701
+ return found;
702
+ });
703
+ if (notFoundConfigNames.length > 0) {
704
+ this.getLogger().error(notFoundConfigNames.map((configName)=>`Configuration with the name "${configName}" was not found.`).join(" "));
705
+ process.exit(2);
706
+ }
707
+ }
708
+ return loadedConfig;
709
+ }
710
+ isMultipleCompiler(compiler) {
711
+ return Boolean(compiler.compilers);
712
+ }
713
+ isWatch(compiler) {
714
+ return Boolean(this.isMultipleCompiler(compiler) ? compiler.compilers.some((compiler)=>compiler.options.watch) : compiler.options.watch);
715
+ }
716
+ constructor(){
717
+ _define_property(this, "colors", void 0);
718
+ _define_property(this, "program", void 0);
719
+ this.colors = this.createColors();
720
+ this.program = external_yargs_default()();
708
721
  }
709
- return loadedConfig;
710
- }
711
- isMultipleCompiler(compiler) {
712
- return Boolean(compiler.compilers);
713
722
  }
714
- isWatch(compiler) {
715
- return Boolean(this.isMultipleCompiler(compiler) ? compiler.compilers.some((compiler)=>compiler.options.watch) : compiler.options.watch);
723
+ function defineConfig(config) {
724
+ return config;
716
725
  }
717
- constructor(){
718
- _define_property(this, "colors", void 0);
719
- _define_property(this, "program", void 0);
720
- this.colors = this.createColors();
721
- this.program = external_yargs_default()();
726
+ function definePlugin(plugin) {
727
+ return plugin;
722
728
  }
723
- }
724
- function defineConfig(config) {
725
- return config;
726
- }
727
- function definePlugin(plugin) {
728
- return plugin;
729
- }
729
+ })();
730
730
  var __webpack_export_target__ = exports;
731
731
  for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
732
732
  if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {