@rspack/cli 1.7.0-beta.0 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const __rslib_import_meta_url__ = /*#__PURE__*/ function() {
2
- return 'undefined' == typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
2
+ return "u" < typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
3
3
  }();
4
4
  var __webpack_modules__ = {
5
5
  "../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js" (module) {
@@ -129,14 +129,14 @@ var __webpack_modules__ = {
129
129
  }
130
130
  exports1.addHook = addHook;
131
131
  },
132
- "./src/utils/rspackCore.ts" (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
132
+ "./src/utils/rspackCore.ts" (__unused_rspack_module, __webpack_exports__, __webpack_require__) {
133
133
  "use strict";
134
134
  __webpack_require__.d(__webpack_exports__, {
135
135
  Z: ()=>rspack
136
136
  });
137
137
  const external_node_module_namespaceObject = require("node:module");
138
138
  const rspackCore_require = (0, external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__);
139
- const rspack = rspackCore_require("@rspack/core");
139
+ const rspack = rspackCore_require('@rspack/core');
140
140
  },
141
141
  module (module) {
142
142
  "use strict";
@@ -201,7 +201,7 @@ __webpack_require__.m = __webpack_modules__;
201
201
  })();
202
202
  (()=>{
203
203
  __webpack_require__.r = (exports1)=>{
204
- if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
204
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
205
205
  value: 'Module'
206
206
  });
207
207
  Object.defineProperty(exports1, '__esModule', {
@@ -732,53 +732,53 @@ ${section.body}` : section.body).join("\n\n"));
732
732
  var picocolors = __webpack_require__("../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js");
733
733
  var external_node_fs_ = __webpack_require__("node:fs");
734
734
  var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_);
735
- const commonOptions = (command)=>command.option("-c, --config <path>", "config file").option("--config-name <name>", "Name(s) of the configuration to use.", {
735
+ const commonOptions = (command)=>command.option('-c, --config <path>', 'config file').option('--config-name <name>', 'Name(s) of the configuration to use.', {
736
736
  type: [
737
737
  String
738
738
  ],
739
739
  default: []
740
- }).option("--config-loader <loader>", "Specify the loader to load the config file, can be `native` or `register`.", {
741
- default: "register"
742
- }).option("--env <env>", "env passed to config function", {
740
+ }).option('--config-loader <loader>', 'Specify the loader to load the config file, can be `native` or `register`.', {
741
+ default: 'register'
742
+ }).option('--env <env>', 'env passed to config function', {
743
743
  type: [
744
744
  String
745
745
  ],
746
746
  default: []
747
- }).option("--node-env <value>", "sets `process.env.NODE_ENV` to be specified value");
747
+ }).option('--node-env <value>', 'sets `process.env.NODE_ENV` to be specified value');
748
748
  function normalizeDevtoolOption(value) {
749
- if ("string" == typeof value) {
749
+ if ('string' == typeof value) {
750
750
  const trimmed = value.trim();
751
- if ("" === trimmed || "false" === trimmed) return false;
752
- if ("true" === trimmed) return "source-map";
751
+ if ('' === trimmed || 'false' === trimmed) return false;
752
+ if ('true' === trimmed) return 'source-map';
753
753
  return trimmed;
754
754
  }
755
- if ("boolean" == typeof value) return value ? "source-map" : false;
755
+ if ('boolean' == typeof value) return value ? 'source-map' : false;
756
756
  }
757
757
  const normalizeCommonOptions = (options, action)=>{
758
758
  const isEmptyArray = (arr)=>Array.isArray(arr) && 0 === arr.length;
759
759
  for (const key of [
760
- "entry",
761
- "configName"
760
+ 'entry',
761
+ 'configName'
762
762
  ]){
763
763
  const val = options[key];
764
764
  if (isEmptyArray(val)) options[key] = void 0;
765
765
  }
766
766
  const env = Array.isArray(options.env) ? normalizeEnvToObject(options) : {};
767
767
  options.env = env;
768
- if ("serve" === action) setBuiltinEnvArg(env, "SERVE", true);
769
- else if ("build" === action) if (options.watch) setBuiltinEnvArg(env, "WATCH", true);
768
+ if ('serve' === action) setBuiltinEnvArg(env, 'SERVE', true);
769
+ else if ('build' === action) if (options.watch) setBuiltinEnvArg(env, 'WATCH', true);
770
770
  else {
771
- setBuiltinEnvArg(env, "BUNDLE", true);
772
- setBuiltinEnvArg(env, "BUILD", true);
771
+ setBuiltinEnvArg(env, 'BUNDLE', true);
772
+ setBuiltinEnvArg(env, 'BUILD', true);
773
773
  }
774
- if ("devtool" in options) options.devtool = normalizeDevtoolOption(options.devtool);
774
+ if ('devtool' in options) options.devtool = normalizeDevtoolOption(options.devtool);
775
775
  };
776
- const commonOptionsForBuildAndServe = (command)=>command.option("--analyze", "analyze").option("-d, --devtool <value>", "specify a developer tool for debugging. Defaults to `cheap-module-source-map` in development and `source-map` in production.").option("--entry <entry>", "entry file", {
776
+ const commonOptionsForBuildAndServe = (command)=>command.option('--analyze', 'analyze').option('-d, --devtool <value>', 'specify a developer tool for debugging. Defaults to `cheap-module-source-map` in development and `source-map` in production.').option('--entry <entry>', 'entry file', {
777
777
  type: [
778
778
  String
779
779
  ],
780
780
  default: []
781
- }).option("-m, --mode <mode>", "mode").option("-o, --output-path <dir>", "output path dir").option("--profile", "capture timing information for each module").option("-w, --watch", "watch");
781
+ }).option('-m, --mode <mode>', 'mode').option('-o, --output-path <dir>', 'output path dir').option('--profile', 'capture timing information for each module').option('-w, --watch', 'watch');
782
782
  function setBuiltinEnvArg(env, envNameSuffix, value) {
783
783
  const envName = `RSPACK_${envNameSuffix}`;
784
784
  if (!(envName in env)) env[envName] = value;
@@ -790,13 +790,13 @@ ${section.body}` : section.body).join("\n\n"));
790
790
  let prevRef = previous;
791
791
  splitKeys.forEach((key, index)=>{
792
792
  let someKey = key;
793
- if (someKey.endsWith("=")) {
793
+ if (someKey.endsWith('=')) {
794
794
  someKey = someKey.slice(0, -1);
795
795
  prevRef[someKey] = void 0;
796
796
  return;
797
797
  }
798
- if (!prevRef[someKey] || "string" == typeof prevRef[someKey]) prevRef[someKey] = {};
799
- if (index === splitKeys.length - 1) if ("string" == typeof val) prevRef[someKey] = val;
798
+ if (!prevRef[someKey] || 'string' == typeof prevRef[someKey]) prevRef[someKey] = {};
799
+ if (index === splitKeys.length - 1) if ('string' == typeof val) prevRef[someKey] = val;
800
800
  else prevRef[someKey] = true;
801
801
  prevRef = prevRef[someKey];
802
802
  });
@@ -805,11 +805,11 @@ ${section.body}` : section.body).join("\n\n"));
805
805
  return (options.env ?? []).reduce(parseValue, {});
806
806
  }
807
807
  function setDefaultNodeEnv(options, defaultEnv) {
808
- if (void 0 === process.env.NODE_ENV) process.env.NODE_ENV = "string" == typeof options.nodeEnv ? options.nodeEnv : defaultEnv;
808
+ if (void 0 === process.env.NODE_ENV) process.env.NODE_ENV = 'string' == typeof options.nodeEnv ? options.nodeEnv : defaultEnv;
809
809
  }
810
810
  async function runBuild(cli, options) {
811
- setDefaultNodeEnv(options, "production");
812
- normalizeCommonOptions(options, "build");
811
+ setDefaultNodeEnv(options, 'production');
812
+ normalizeCommonOptions(options, 'build');
813
813
  const logger = cli.getLogger();
814
814
  let createJsonStringifyStream;
815
815
  if (options.json) {
@@ -835,8 +835,8 @@ ${section.body}` : section.body).join("\n\n"));
835
835
  logger.error(error);
836
836
  process.exit(2);
837
837
  };
838
- if (true === options.json) createJsonStringifyStream(stats.toJson(statsOptions)).on("error", handleWriteError).pipe(process.stdout).on("error", handleWriteError).on("close", ()=>process.stdout.write("\n"));
839
- else if ("string" == typeof options.json) createJsonStringifyStream(stats.toJson(statsOptions)).on("error", handleWriteError).pipe(external_node_fs_default().createWriteStream(options.json)).on("error", handleWriteError).on("close", ()=>{
838
+ if (true === options.json) createJsonStringifyStream(stats.toJson(statsOptions)).on('error', handleWriteError).pipe(process.stdout).on('error', handleWriteError).on('close', ()=>process.stdout.write('\n'));
839
+ else if ('string' == typeof options.json) createJsonStringifyStream(stats.toJson(statsOptions)).on('error', handleWriteError).pipe(external_node_fs_default().createWriteStream(options.json)).on('error', handleWriteError).on('close', ()=>{
840
840
  process.stderr.write(`[rspack-cli] ${cli.colors.green(`stats are successfully stored as json to ${options.json}`)}\n`);
841
841
  });
842
842
  } else {
@@ -844,7 +844,8 @@ ${section.body}` : section.body).join("\n\n"));
844
844
  if (printedStats) logger.raw(printedStats);
845
845
  }
846
846
  };
847
- const compiler = await cli.createCompiler(options, "build", errorHandler);
847
+ const userOption = await cli.buildCompilerConfig(options, 'build');
848
+ const compiler = await cli.createCompiler(userOption, errorHandler);
848
849
  if (!compiler || cli.isWatch(compiler)) return;
849
850
  compiler.run((error, stats)=>{
850
851
  compiler.close((closeErr)=>{
@@ -855,8 +856,8 @@ ${section.body}` : section.body).join("\n\n"));
855
856
  }
856
857
  class BuildCommand {
857
858
  async apply(cli) {
858
- const command = cli.program.command("", "run the Rspack build").alias("build").alias("bundle").alias("b");
859
- commonOptionsForBuildAndServe(commonOptions(command)).option("--json [path]", "emit stats json");
859
+ const command = cli.program.command('', 'run the Rspack build').alias('build').alias('bundle').alias('b');
860
+ commonOptionsForBuildAndServe(commonOptions(command)).option('--json [path]', 'emit stats json');
860
861
  command.action(async (options)=>{
861
862
  await runBuild(cli, options);
862
863
  });
@@ -865,11 +866,11 @@ ${section.body}` : section.body).join("\n\n"));
865
866
  var rspackCore = __webpack_require__("./src/utils/rspackCore.ts");
866
867
  class PreviewCommand {
867
868
  async apply(cli) {
868
- const command = cli.program.command("preview [dir]", "run the Rspack server for build output").alias("p");
869
- commonOptions(command).option("--public-path <path>", "static resource server path").option("--port <port>", "preview server port").option("--host <host>", "preview server host").option("--open", "open browser").option("--server <config>", "Configuration items for the server.");
869
+ const command = cli.program.command('preview [dir]', 'run the Rspack server for build output').alias('p');
870
+ commonOptions(command).option('--public-path <path>', 'static resource server path').option('--port <port>', 'preview server port').option('--host <host>', 'preview server host').option('--open', 'open browser').option('--server <config>', 'Configuration items for the server.');
870
871
  command.action(async (dir, options)=>{
871
- setDefaultNodeEnv(options, "production");
872
- normalizeCommonOptions(options, "preview");
872
+ setDefaultNodeEnv(options, 'production');
873
+ normalizeCommonOptions(options, 'preview');
873
874
  const { RspackDevServer } = await import("@rspack/dev-server");
874
875
  let { config } = await cli.loadConfig(options);
875
876
  config = await getPreviewConfig(config, options, dir);
@@ -894,12 +895,12 @@ ${section.body}` : section.body).join("\n\n"));
894
895
  }
895
896
  }
896
897
  async function getPreviewConfig(item, options, dir) {
897
- const DEFAULT_ROOT = "dist";
898
+ const DEFAULT_ROOT = 'dist';
898
899
  const internalPreviewConfig = async (item)=>{
899
900
  item.devServer = {
900
901
  static: {
901
902
  directory: dir ? external_node_path_default().join(item.context ?? process.cwd(), dir) : item.output?.path ?? external_node_path_default().join(item.context ?? process.cwd(), DEFAULT_ROOT),
902
- publicPath: options.publicPath ?? "/"
903
+ publicPath: options.publicPath ?? '/'
903
904
  },
904
905
  port: options.port ?? 8080,
905
906
  proxy: item.devServer?.proxy,
@@ -914,30 +915,41 @@ ${section.body}` : section.body).join("\n\n"));
914
915
  return internalPreviewConfig(item);
915
916
  }
916
917
  function normalizeHotOption(value) {
917
- if ("false" === value) return false;
918
- if ("true" === value) return true;
918
+ if ('false' === value) return false;
919
+ if ('true' === value) return true;
919
920
  return value;
920
921
  }
921
922
  class ServeCommand {
922
923
  async apply(cli) {
923
- const command = cli.program.command("serve", "run the rspack dev server.").alias("server").alias("s").alias("dev");
924
- commonOptionsForBuildAndServe(commonOptions(command)).option("--hot [mode]", "enables hot module replacement").option("--port <port>", "allows to specify a port to use").option("--host <host>", "allows to specify a hostname to use");
924
+ const command = cli.program.command('serve', 'run the rspack dev server.').alias('server').alias('s').alias('dev');
925
+ commonOptionsForBuildAndServe(commonOptions(command)).option('--hot [mode]', 'enables hot module replacement').option('--port <port>', 'allows to specify a port to use').option('--host <host>', 'allows to specify a hostname to use');
925
926
  command.action(async (cliOptions)=>{
926
- setDefaultNodeEnv(cliOptions, "development");
927
- normalizeCommonOptions(cliOptions, "serve");
927
+ setDefaultNodeEnv(cliOptions, 'development');
928
+ normalizeCommonOptions(cliOptions, 'serve');
928
929
  cliOptions.hot = normalizeHotOption(cliOptions.hot);
929
930
  const { RspackDevServer } = await import("@rspack/dev-server");
930
- const compiler = await cli.createCompiler(cliOptions, "serve");
931
+ const userConfig = await cli.buildCompilerConfig(cliOptions, 'serve');
932
+ const compiler = await cli.createCompiler(userConfig);
931
933
  if (!compiler) return;
932
- const compilers = cli.isMultipleCompiler(compiler) ? compiler.compilers : [
934
+ const isMultiCompiler = cli.isMultipleCompiler(compiler);
935
+ const compilers = isMultiCompiler ? compiler.compilers : [
933
936
  compiler
934
937
  ];
938
+ const userConfigs = isMultiCompiler ? userConfig : [
939
+ userConfig
940
+ ];
935
941
  const possibleCompilers = compilers.filter((compiler)=>compiler.options.devServer);
936
942
  const usedPorts = [];
937
943
  const servers = [];
938
944
  const compilerForDevServer = possibleCompilers.length > 0 ? possibleCompilers[0] : compilers[0];
939
- for (const compiler of compilers){
945
+ for (const [index, compiler] of compilers.entries()){
946
+ const userConfig = userConfigs[index];
940
947
  const devServer = compiler.options.devServer ??= {};
948
+ const isWebAppOnly = compiler.platform.web && !compiler.platform.node && !compiler.platform.nwjs && !compiler.platform.electron && !compiler.platform.webworker;
949
+ if (isWebAppOnly && void 0 === userConfig.lazyCompilation) compiler.options.lazyCompilation = {
950
+ imports: true,
951
+ entries: false
952
+ };
941
953
  devServer.hot = cliOptions.hot ?? devServer.hot ?? true;
942
954
  if (false !== devServer.client) {
943
955
  if (true === devServer.client || null == devServer.client) devServer.client = {};
@@ -977,7 +989,7 @@ ${section.body}` : section.body).join("\n\n"));
977
989
  if (devServerOptions.port) {
978
990
  const portNumber = Number(devServerOptions.port);
979
991
  if (!Number.isNaN(portNumber)) {
980
- 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.");
992
+ 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.');
981
993
  usedPorts.push(portNumber);
982
994
  }
983
995
  }
@@ -997,15 +1009,15 @@ ${section.body}` : section.body).join("\n\n"));
997
1009
  const external_node_url_namespaceObject = require("node:url");
998
1010
  const readPackageUp = (cwd = process.cwd())=>{
999
1011
  let currentDir = external_node_path_default().resolve(cwd);
1000
- let packageJsonPath = external_node_path_default().join(currentDir, "package.json");
1012
+ let packageJsonPath = external_node_path_default().join(currentDir, 'package.json');
1001
1013
  while(!external_node_fs_default().existsSync(packageJsonPath)){
1002
1014
  const parentDir = external_node_path_default().dirname(currentDir);
1003
1015
  if (parentDir === currentDir) return null;
1004
1016
  currentDir = parentDir;
1005
- packageJsonPath = external_node_path_default().join(currentDir, "package.json");
1017
+ packageJsonPath = external_node_path_default().join(currentDir, 'package.json');
1006
1018
  }
1007
1019
  try {
1008
- return JSON.parse(external_node_fs_default().readFileSync(packageJsonPath, "utf8"));
1020
+ return JSON.parse(external_node_fs_default().readFileSync(packageJsonPath, 'utf8'));
1009
1021
  } catch {
1010
1022
  return null;
1011
1023
  }
@@ -1015,7 +1027,7 @@ ${section.body}` : section.body).join("\n\n"));
1015
1027
  if (/\.(mjs|mts)$/.test(filePath)) return true;
1016
1028
  if (/\.(cjs|cts)$/.test(filePath)) return false;
1017
1029
  const packageJson = utils_readPackageUp(external_node_path_default().dirname(filePath));
1018
- return packageJson?.type === "module";
1030
+ return packageJson?.type === 'module';
1019
1031
  };
1020
1032
  const crossImport = async (path)=>{
1021
1033
  if (isEsmFile(path)) {
@@ -1024,23 +1036,23 @@ ${section.body}` : section.body).join("\n\n"));
1024
1036
  return config;
1025
1037
  }
1026
1038
  let result = require(path);
1027
- if (result && "object" == typeof result && "default" in result) result = result.default || {};
1039
+ if (result && 'object' == typeof result && 'default' in result) result = result.default || {};
1028
1040
  return result;
1029
1041
  };
1030
1042
  const DEFAULT_EXTENSIONS = [
1031
- ".js",
1032
- ".ts",
1033
- ".mjs",
1034
- ".mts",
1035
- ".cjs",
1036
- ".cts"
1043
+ '.js',
1044
+ '.ts',
1045
+ '.mjs',
1046
+ '.mts',
1047
+ '.cjs',
1048
+ '.cts'
1037
1049
  ];
1038
1050
  const findConfig = (basePath)=>DEFAULT_EXTENSIONS.map((ext)=>basePath + ext).find(external_node_fs_default().existsSync);
1039
1051
  const utils_findConfig = findConfig;
1040
1052
  const TS_EXTENSION = [
1041
- ".ts",
1042
- ".cts",
1043
- ".mts"
1053
+ '.ts',
1054
+ '.cts',
1055
+ '.mts'
1044
1056
  ];
1045
1057
  const isTsFile = (configPath)=>{
1046
1058
  const ext = external_node_path_default().extname(configPath);
@@ -1049,7 +1061,7 @@ ${section.body}` : section.body).join("\n\n"));
1049
1061
  const utils_isTsFile = isTsFile;
1050
1062
  const injectInlineSourceMap = ({ code, map })=>{
1051
1063
  if (map) {
1052
- const base64Map = Buffer.from(map, "utf8").toString("base64");
1064
+ const base64Map = Buffer.from(map, 'utf8').toString('base64');
1053
1065
  const sourceMapContent = `//# sourceMappingURL=data:application/json;charset=utf-8;base64,${base64Map}`;
1054
1066
  return `${code}\n${sourceMapContent}`;
1055
1067
  }
@@ -1067,7 +1079,7 @@ ${section.body}` : section.body).join("\n\n"));
1067
1079
  },
1068
1080
  filename: filename,
1069
1081
  module: {
1070
- type: "commonjs"
1082
+ type: 'commonjs'
1071
1083
  },
1072
1084
  sourceMaps: true,
1073
1085
  isModule: true
@@ -1077,7 +1089,7 @@ ${section.body}` : section.body).join("\n\n"));
1077
1089
  map
1078
1090
  });
1079
1091
  }
1080
- const loadConfig_DEFAULT_CONFIG_NAME = "rspack.config";
1092
+ const loadConfig_DEFAULT_CONFIG_NAME = 'rspack.config';
1081
1093
  const registerLoader = (configPath)=>{
1082
1094
  if (isEsmFile(configPath) && utils_isTsFile(configPath)) return;
1083
1095
  if (!utils_isTsFile(configPath)) throw new Error(`config file "${configPath}" is not supported.`);
@@ -1110,7 +1122,7 @@ ${section.body}` : section.body).join("\n\n"));
1110
1122
  pathMap.set(config, [
1111
1123
  configPath
1112
1124
  ]);
1113
- if (!("extends" in config) || !config.extends) return {
1125
+ if (!('extends' in config) || !config.extends) return {
1114
1126
  config,
1115
1127
  pathMap
1116
1128
  };
@@ -1125,7 +1137,7 @@ ${section.body}` : section.body).join("\n\n"));
1125
1137
  ]);
1126
1138
  for (const extendPath of extendsList){
1127
1139
  let resolvedPath;
1128
- if (extendPath.startsWith(".") || extendPath.startsWith("/") || extendPath.includes(":\\")) {
1140
+ if (extendPath.startsWith('.') || extendPath.startsWith('/') || extendPath.includes(':\\')) {
1129
1141
  resolvedPath = external_node_path_default().resolve(baseDir, extendPath);
1130
1142
  if (!external_node_path_default().extname(resolvedPath)) {
1131
1143
  const foundConfig = utils_findConfig(resolvedPath);
@@ -1143,11 +1155,11 @@ ${section.body}` : section.body).join("\n\n"));
1143
1155
  throw new Error(`Cannot find module '${extendPath}' to extend from.`);
1144
1156
  }
1145
1157
  if (!external_node_fs_default().existsSync(resolvedPath)) throw new Error(`Extended configuration file "${resolvedPath}" not found.`);
1146
- if (utils_isTsFile(resolvedPath) && "register" === options.configLoader) registerLoader(resolvedPath);
1158
+ if (utils_isTsFile(resolvedPath) && 'register' === options.configLoader) registerLoader(resolvedPath);
1147
1159
  let loadedConfig = await crossImport(resolvedPath);
1148
- if ("function" == typeof loadedConfig) {
1160
+ if ('function' == typeof loadedConfig) {
1149
1161
  loadedConfig = loadedConfig(options.env, options);
1150
- if ("function" == typeof loadedConfig.then) loadedConfig = await loadedConfig;
1162
+ if ('function' == typeof loadedConfig.then) loadedConfig = await loadedConfig;
1151
1163
  }
1152
1164
  const { config: extendedConfig, pathMap: extendedPathMap } = await loadExtendedConfig(loadedConfig, resolvedPath, cwd, options);
1153
1165
  const configPaths = [
@@ -1163,7 +1175,7 @@ ${section.body}` : section.body).join("\n\n"));
1163
1175
  };
1164
1176
  }
1165
1177
  async function loadRspackConfig(options, cwd = process.cwd()) {
1166
- let configPath = "";
1178
+ let configPath = '';
1167
1179
  if (options.config) {
1168
1180
  configPath = external_node_path_default().resolve(cwd, options.config);
1169
1181
  if (!external_node_fs_default().existsSync(configPath)) throw new Error(`config file "${configPath}" not found.`);
@@ -1172,7 +1184,7 @@ ${section.body}` : section.body).join("\n\n"));
1172
1184
  if (!defaultConfig) return null;
1173
1185
  configPath = defaultConfig;
1174
1186
  }
1175
- if (utils_isTsFile(configPath) && "register" === options.configLoader) registerLoader(configPath);
1187
+ if (utils_isTsFile(configPath) && 'register' === options.configLoader) registerLoader(configPath);
1176
1188
  const loadedConfig = await crossImport(configPath);
1177
1189
  return {
1178
1190
  loadedConfig,
@@ -1183,15 +1195,18 @@ ${section.body}` : section.body).join("\n\n"));
1183
1195
  colors;
1184
1196
  program;
1185
1197
  constructor(){
1186
- const program = dist("rspack");
1198
+ const program = dist('rspack');
1187
1199
  this.colors = this.createColors();
1188
1200
  this.program = program;
1189
1201
  program.help();
1190
- program.version("1.7.0-beta.0");
1202
+ program.version("1.7.0");
1191
1203
  }
1192
- async createCompiler(options, rspackCommand, callback) {
1204
+ async buildCompilerConfig(options, rspackCommand) {
1193
1205
  let { config, pathMap } = await this.loadConfig(options);
1194
1206
  config = await this.buildConfig(config, pathMap, options, rspackCommand);
1207
+ return config;
1208
+ }
1209
+ async createCompiler(config, callback) {
1195
1210
  const isWatch = Array.isArray(config) ? config.some((i)=>i.watch) : config.watch;
1196
1211
  let compiler;
1197
1212
  try {
@@ -1202,7 +1217,7 @@ ${section.body}` : section.body).join("\n\n"));
1202
1217
  this.getLogger().error(e.message);
1203
1218
  process.exit(2);
1204
1219
  } else if (e instanceof Error) {
1205
- if ("function" == typeof callback) callback(e);
1220
+ if ('function' == typeof callback) callback(e);
1206
1221
  else this.getLogger().error(e);
1207
1222
  return null;
1208
1223
  }
@@ -1240,8 +1255,8 @@ ${section.body}` : section.body).join("\n\n"));
1240
1255
  for (const command of builtinCommands)await command.apply(this);
1241
1256
  }
1242
1257
  async buildConfig(item, pathMap, options, command) {
1243
- const isBuild = "build" === command;
1244
- const isServe = "serve" === command;
1258
+ const isBuild = 'build' === command;
1259
+ const isServe = 'serve' === command;
1245
1260
  const internalBuildConfig = async (item)=>{
1246
1261
  if (options.entry) item.entry = {
1247
1262
  main: options.entry.map((x)=>external_node_path_default().resolve(process.cwd(), x))[0]
@@ -1251,7 +1266,7 @@ ${section.body}` : section.body).join("\n\n"));
1251
1266
  if (options.analyze) {
1252
1267
  const { BundleAnalyzerPlugin } = await import("webpack-bundle-analyzer");
1253
1268
  (item.plugins ??= []).push({
1254
- name: "rspack-bundle-analyzer",
1269
+ name: 'rspack-bundle-analyzer',
1255
1270
  apply (compiler) {
1256
1271
  new BundleAnalyzerPlugin({
1257
1272
  generateStatsFile: true
@@ -1265,16 +1280,16 @@ ${section.body}` : section.body).join("\n\n"));
1265
1280
  await applyProfile(process.env.RSPACK_PROFILE, process.env.RSPACK_TRACE_LAYER, process.env.RSPACK_TRACE_OUTPUT);
1266
1281
  }
1267
1282
  if (options.watch) item.watch = options.watch;
1268
- if (!item.mode) item.mode = isBuild ? "production" : "development";
1283
+ if (!item.mode) item.mode = isBuild ? 'production' : 'development';
1269
1284
  if (options.mode) item.mode = options.mode;
1270
- if (void 0 === item.devtool) item.devtool = isBuild ? "source-map" : "cheap-module-source-map";
1285
+ if (void 0 === item.devtool) item.devtool = isBuild ? 'source-map' : 'cheap-module-source-map';
1271
1286
  if (void 0 !== options.devtool) item.devtool = options.devtool;
1272
1287
  if (isServe) {
1273
1288
  const installed = (item.plugins ||= []).find((item)=>item instanceof rspackCore.Z.ProgressPlugin);
1274
1289
  if (!installed) (item.plugins ??= []).push(new rspackCore.Z.ProgressPlugin());
1275
1290
  }
1276
1291
  const cacheOptions = item.experiments?.cache;
1277
- if ("object" == typeof cacheOptions && "persistent" === cacheOptions.type) {
1292
+ if ('object' == typeof cacheOptions && 'persistent' === cacheOptions.type) {
1278
1293
  const configPaths = pathMap.get(item);
1279
1294
  if (configPaths) cacheOptions.buildDependencies = [
1280
1295
  ...configPaths,
@@ -1282,15 +1297,15 @@ ${section.body}` : section.body).join("\n\n"));
1282
1297
  ];
1283
1298
  }
1284
1299
  if (void 0 === item.stats) item.stats = {
1285
- preset: "errors-warnings",
1300
+ preset: 'errors-warnings',
1286
1301
  timings: true
1287
1302
  };
1288
- else if ("boolean" == typeof item.stats) item.stats = item.stats ? {
1289
- preset: "normal"
1303
+ else if ('boolean' == typeof item.stats) item.stats = item.stats ? {
1304
+ preset: 'normal'
1290
1305
  } : {
1291
- preset: "none"
1306
+ preset: 'none'
1292
1307
  };
1293
- else if ("string" == typeof item.stats) item.stats = {
1308
+ else if ('string' == typeof item.stats) item.stats = {
1294
1309
  preset: item.stats
1295
1310
  };
1296
1311
  if (this.colors.isColorSupported && void 0 === item.stats.colors) item.stats.colors = true;
@@ -1306,9 +1321,9 @@ ${section.body}` : section.body).join("\n\n"));
1306
1321
  pathMap: new WeakMap()
1307
1322
  };
1308
1323
  let { loadedConfig, configPath } = config;
1309
- if ("function" == typeof loadedConfig) {
1324
+ if ('function' == typeof loadedConfig) {
1310
1325
  let functionResult = loadedConfig(options.env, options);
1311
- if ("function" == typeof functionResult.then) functionResult = await functionResult;
1326
+ if ('function' == typeof functionResult.then) functionResult = await functionResult;
1312
1327
  loadedConfig = functionResult;
1313
1328
  }
1314
1329
  const { config: extendedConfig, pathMap } = await loadExtendedConfig(loadedConfig, configPath, process.cwd(), options);
@@ -1327,7 +1342,7 @@ ${section.body}` : section.body).join("\n\n"));
1327
1342
  return found;
1328
1343
  });
1329
1344
  if (notFoundConfigNames.length > 0) {
1330
- this.getLogger().error(notFoundConfigNames.map((configName)=>`Configuration with the name "${configName}" was not found.`).join(" "));
1345
+ this.getLogger().error(notFoundConfigNames.map((configName)=>`Configuration with the name "${configName}" was not found.`).join(' '));
1331
1346
  process.exit(2);
1332
1347
  }
1333
1348
  }