@rspack/cli 1.2.2 → 1.2.4

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