@nx/rspack 20.4.0-beta.0 → 20.4.0-beta.2

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nx/rspack",
3
3
  "description": "The Nx Plugin for Rspack contains executors and generators that support building applications using Rspack.",
4
- "version": "20.4.0-beta.0",
4
+ "version": "20.4.0-beta.2",
5
5
  "type": "commonjs",
6
6
  "repository": {
7
7
  "type": "git",
@@ -24,17 +24,16 @@
24
24
  "generators": "./generators.json",
25
25
  "executors": "./executors.json",
26
26
  "dependencies": {
27
- "@nx/js": "20.4.0-beta.0",
28
- "@nx/devkit": "20.4.0-beta.0",
29
- "@nx/web": "20.4.0-beta.0",
30
- "@nx/module-federation": "20.4.0-beta.0",
27
+ "@nx/js": "20.4.0-beta.2",
28
+ "@nx/devkit": "20.4.0-beta.2",
29
+ "@nx/web": "20.4.0-beta.2",
30
+ "@nx/module-federation": "20.4.0-beta.2",
31
31
  "@phenomnomnominal/tsquery": "~5.0.1",
32
32
  "@rspack/core": "^1.1.5",
33
33
  "@rspack/dev-server": "^1.0.9",
34
34
  "@rspack/plugin-react-refresh": "^1.0.0",
35
35
  "autoprefixer": "^10.4.9",
36
36
  "browserslist": "^4.21.4",
37
- "chalk": "~4.1.0",
38
37
  "css-loader": "^6.4.0",
39
38
  "enquirer": "~2.3.6",
40
39
  "express": "^4.19.2",
@@ -47,6 +46,7 @@
47
46
  "sass-loader": "^12.2.0",
48
47
  "source-map-loader": "^5.0.0",
49
48
  "style-loader": "^3.3.0",
49
+ "picocolors": "^1.1.0",
50
50
  "postcss-import": "~14.1.0",
51
51
  "postcss-loader": "^8.1.1",
52
52
  "postcss": "^8.4.38",
@@ -4,7 +4,7 @@ exports.ssrDevServerExecutor = ssrDevServerExecutor;
4
4
  const tslib_1 = require("tslib");
5
5
  const devkit_1 = require("@nx/devkit");
6
6
  const async_iterable_1 = require("@nx/devkit/src/utils/async-iterable");
7
- const chalk = tslib_1.__importStar(require("chalk"));
7
+ const pc = tslib_1.__importStar(require("picocolors"));
8
8
  const wait_until_server_is_listening_1 = require("./lib/wait-until-server-is-listening");
9
9
  async function* ssrDevServerExecutor(options, context) {
10
10
  const browserTarget = (0, devkit_1.parseTargetString)(options.browserTarget, context.projectGraph);
@@ -27,7 +27,7 @@ async function* ssrDevServerExecutor(options, context) {
27
27
  }
28
28
  if (nodeStarted && browserBuilt) {
29
29
  await (0, wait_until_server_is_listening_1.waitUntilServerIsListening)(options.port);
30
- console.log(`[ ${chalk.green('ready')} ] on http://localhost:${options.port}`);
30
+ console.log(`[ ${pc.green('ready')} ] on http://localhost:${options.port}`);
31
31
  yield {
32
32
  ...output,
33
33
  baseUrl: `http://localhost:${options.port}`,
@@ -6,6 +6,7 @@ const devkit_1 = require("@nx/devkit");
6
6
  const generator_utils_1 = require("../../utils/generator-utils");
7
7
  const create_ts_config_1 = require("../application/lib/create-ts-config");
8
8
  const init_1 = tslib_1.__importDefault(require("../init/init"));
9
+ const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
9
10
  async function configurationGenerator(tree, options) {
10
11
  const task = await (0, init_1.default)(tree, {
11
12
  ...options,
@@ -34,7 +35,7 @@ async function configurationGenerator(tree, options) {
34
35
  projectAlreadyHasRspackTargets = alreadyHasNxRspackTargets;
35
36
  if (alreadyHasNxRspackTargets.build &&
36
37
  (alreadyHasNxRspackTargets.serve ||
37
- projectType === 'library' ||
38
+ (0, ts_solution_setup_1.getProjectType)(tree, options.project, projectType) === 'library' ||
38
39
  options.framework === 'nest')) {
39
40
  throw new Error(`The project ${options.project} is already configured to use the @nx/rspack executors.
40
41
  Please try a different project, or remove the existing targets
@@ -68,7 +68,12 @@ async function createRspackTargets(configFilePath, projectRoot, options, context
68
68
  const namedInputs = (0, get_named_inputs_1.getNamedInputs)(projectRoot, context);
69
69
  const rspackConfig = (0, resolve_user_defined_rspack_config_1.resolveUserDefinedRspackConfig)((0, path_1.join)(context.workspaceRoot, configFilePath), (0, js_1.getRootTsConfigPath)(), true);
70
70
  const rspackOptions = await (0, read_rspack_options_1.readRspackOptions)(rspackConfig);
71
- const outputPath = normalizeOutputPath(rspackOptions.output?.path, projectRoot);
71
+ const outputs = [];
72
+ for (const config of rspackOptions) {
73
+ if (config.output?.path) {
74
+ outputs.push(normalizeOutputPath(config.output.path, projectRoot));
75
+ }
76
+ }
72
77
  const targets = {};
73
78
  targets[options.buildTargetName] = {
74
79
  command: `rspack build`,
@@ -90,7 +95,7 @@ async function createRspackTargets(configFilePath, projectRoot, options, context
90
95
  externalDependencies: ['@rspack/cli'],
91
96
  },
92
97
  ],
93
- outputs: [outputPath],
98
+ outputs,
94
99
  };
95
100
  targets[options.serveTargetName] = {
96
101
  command: `rspack serve`,
@@ -184,7 +184,10 @@ function createConfig(tree, options) {
184
184
  const project = (0, devkit_1.readProjectConfiguration)(tree, options.project);
185
185
  const buildOptions = createBuildOptions(tree, options, project);
186
186
  const defaultConfig = generateDefaultConfig(project, buildOptions);
187
- if (isWebFramework(options)) {
187
+ if (options.framework === 'react') {
188
+ return generateReactConfig(options);
189
+ }
190
+ else if (isWebFramework(options)) {
188
191
  return generateWebConfig(tree, options, defaultConfig);
189
192
  }
190
193
  else if (options.framework === 'nest') {
@@ -242,6 +245,21 @@ module.exports = composePlugins(withNx(), withWeb(${options.stylePreprocessorOpt
242
245
  });
243
246
  `;
244
247
  }
248
+ function generateReactConfig({ stylePreprocessorOptions, }) {
249
+ return `
250
+ const { composePlugins, withNx, withReact } = require('@nx/rspack');
251
+
252
+ module.exports = composePlugins(withNx(), withReact(${stylePreprocessorOptions
253
+ ? `
254
+ {
255
+ stylePreprocessorOptions: ${JSON.stringify(stylePreprocessorOptions)},
256
+ }
257
+ `
258
+ : ''}), (config) => {
259
+ return config;
260
+ });
261
+ `;
262
+ }
245
263
  function generateNestConfig(tree, options, project, buildOptions) {
246
264
  if ((0, has_plugin_1.hasPlugin)(tree)) {
247
265
  return `
@@ -1,10 +1,11 @@
1
1
  import { Configuration } from '@rspack/core';
2
2
  /**
3
3
  * Reads the Rspack options from a give Rspack configuration. The configuration can be:
4
- * 1. A standard config object
5
- * 2. A standard function that returns a config object
6
- * 3. A Nx-specific composable function that takes Nx context, rspack config, and returns the config object.
4
+ * 1. A single standard config object
5
+ * 2. A standard function that returns a config object (standard Rspack)
6
+ * 3. An array of standard config objects (multi-configuration mode)
7
+ * 4. A Nx-specific composable function that takes Nx context, rspack config, and returns the config object.
7
8
  *
8
9
  * @param rspackConfig
9
10
  */
10
- export declare function readRspackOptions(rspackConfig: unknown): Promise<Configuration>;
11
+ export declare function readRspackOptions(rspackConfig: unknown): Promise<Configuration[]>;
@@ -6,47 +6,76 @@ const config_1 = require("./config");
6
6
  const devkit_internals_1 = require("nx/src/devkit-internals");
7
7
  /**
8
8
  * Reads the Rspack options from a give Rspack configuration. The configuration can be:
9
- * 1. A standard config object
10
- * 2. A standard function that returns a config object
11
- * 3. A Nx-specific composable function that takes Nx context, rspack config, and returns the config object.
9
+ * 1. A single standard config object
10
+ * 2. A standard function that returns a config object (standard Rspack)
11
+ * 3. An array of standard config objects (multi-configuration mode)
12
+ * 4. A Nx-specific composable function that takes Nx context, rspack config, and returns the config object.
12
13
  *
13
14
  * @param rspackConfig
14
15
  */
15
16
  async function readRspackOptions(rspackConfig) {
16
- let config;
17
- if ((0, config_1.isNxRspackComposablePlugin)(rspackConfig)) {
18
- config = await rspackConfig({}, {
19
- // These values are only used during build-time, so passing stubs here just to read out
20
- // the returned config object.
21
- options: {
22
- root: devkit_1.workspaceRoot,
23
- projectRoot: '',
24
- sourceRoot: '',
25
- outputFileName: '',
26
- assets: [],
27
- main: '',
28
- tsConfig: '',
29
- outputPath: '',
30
- rspackConfig: '',
31
- useTsconfigPaths: undefined,
32
- },
33
- context: {
34
- root: devkit_1.workspaceRoot,
35
- cwd: undefined,
36
- isVerbose: false,
37
- nxJsonConfiguration: (0, devkit_internals_1.readNxJsonFromDisk)(devkit_1.workspaceRoot),
38
- projectGraph: null,
39
- projectsConfigurations: null,
40
- },
41
- });
42
- }
43
- else if (typeof rspackConfig === 'function') {
44
- config = await rspackConfig({
45
- production: true, // we want the production build options
46
- }, {});
17
+ const configs = [];
18
+ const resolveConfig = async (config) => {
19
+ let resolvedConfig;
20
+ if ((0, config_1.isNxRspackComposablePlugin)(config)) {
21
+ resolvedConfig = await config({}, {
22
+ // These values are only used during build-time, so passing stubs here just to read out
23
+ // the returned config object.
24
+ options: {
25
+ root: devkit_1.workspaceRoot,
26
+ projectRoot: '',
27
+ sourceRoot: '',
28
+ outputFileName: '',
29
+ assets: [],
30
+ main: '',
31
+ tsConfig: '',
32
+ outputPath: '',
33
+ rspackConfig: '',
34
+ useTsconfigPaths: undefined,
35
+ },
36
+ context: {
37
+ root: devkit_1.workspaceRoot,
38
+ cwd: undefined,
39
+ isVerbose: false,
40
+ nxJsonConfiguration: (0, devkit_internals_1.readNxJsonFromDisk)(devkit_1.workspaceRoot),
41
+ projectGraph: null,
42
+ projectsConfigurations: null,
43
+ },
44
+ });
45
+ }
46
+ else if (typeof config === 'function') {
47
+ const resolved = await config({
48
+ production: true, // we want the production build options
49
+ }, {});
50
+ // If the resolved configuration is an array, resolve each configuration
51
+ return Array.isArray(resolved)
52
+ ? await Promise.all(resolved.map(resolveConfig))
53
+ : resolved;
54
+ }
55
+ else if (Array.isArray(config)) {
56
+ // If the config passed is an array, resolve each configuration
57
+ const resolvedConfigs = await Promise.all(config.map(resolveConfig));
58
+ return resolvedConfigs.flat();
59
+ }
60
+ else {
61
+ return config;
62
+ }
63
+ };
64
+ // Since configs can have nested arrays, we need to flatten them
65
+ const flattenConfigs = (resolvedConfigs) => {
66
+ return Array.isArray(resolvedConfigs)
67
+ ? resolvedConfigs.flatMap((cfg) => flattenConfigs(cfg))
68
+ : [resolvedConfigs];
69
+ };
70
+ if (Array.isArray(rspackConfig)) {
71
+ for (const config of rspackConfig) {
72
+ const resolved = await resolveConfig(config);
73
+ configs.push(...flattenConfigs(resolved));
74
+ }
47
75
  }
48
76
  else {
49
- config = rspackConfig;
77
+ const resolved = await resolveConfig(rspackConfig);
78
+ configs.push(...flattenConfigs(resolved));
50
79
  }
51
- return config;
80
+ return configs;
52
81
  }
@@ -4,11 +4,7 @@ export declare const rspackDevServerVersion = "1.0.9";
4
4
  export declare const rspackPluginMinifyVersion = "^0.7.5";
5
5
  export declare const rspackPluginReactRefreshVersion = "^1.0.0";
6
6
  export declare const lessLoaderVersion = "~11.1.3";
7
- export declare const reactVersion = "~18.2.0";
8
7
  export declare const reactRefreshVersion = "~0.14.0";
9
- export declare const reactDomVersion = "~18.2.0";
10
- export declare const typesReactVersion = "~18.0.28";
11
- export declare const typesReactDomVersion = "~18.0.10";
12
8
  export declare const nestjsCommonVersion = "~9.0.0";
13
9
  export declare const nestjsCoreVersion = "~9.0.0";
14
10
  export declare const nestjsPlatformExpressVersion = "~9.0.0";
@@ -1,17 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.eslintPluginReactHooksVersion = exports.eslintPluginReactVersion = exports.eslintPluginJsxA11yVersion = exports.eslintPluginImportVersion = exports.stylusVersion = exports.sassVersion = exports.lessVersion = exports.nestjsMicroservicesVersion = exports.nestjsPlatformExpressVersion = exports.nestjsCoreVersion = exports.nestjsCommonVersion = exports.typesReactDomVersion = exports.typesReactVersion = exports.reactDomVersion = exports.reactRefreshVersion = exports.reactVersion = exports.lessLoaderVersion = exports.rspackPluginReactRefreshVersion = exports.rspackPluginMinifyVersion = exports.rspackDevServerVersion = exports.rspackCoreVersion = exports.nxVersion = void 0;
3
+ exports.eslintPluginReactHooksVersion = exports.eslintPluginReactVersion = exports.eslintPluginJsxA11yVersion = exports.eslintPluginImportVersion = exports.stylusVersion = exports.sassVersion = exports.lessVersion = exports.nestjsMicroservicesVersion = exports.nestjsPlatformExpressVersion = exports.nestjsCoreVersion = exports.nestjsCommonVersion = exports.reactRefreshVersion = exports.lessLoaderVersion = exports.rspackPluginReactRefreshVersion = exports.rspackPluginMinifyVersion = exports.rspackDevServerVersion = exports.rspackCoreVersion = exports.nxVersion = void 0;
4
4
  exports.nxVersion = require('../../package.json').version;
5
5
  exports.rspackCoreVersion = '^1.1.5';
6
6
  exports.rspackDevServerVersion = '1.0.9';
7
7
  exports.rspackPluginMinifyVersion = '^0.7.5';
8
8
  exports.rspackPluginReactRefreshVersion = '^1.0.0';
9
9
  exports.lessLoaderVersion = '~11.1.3';
10
- exports.reactVersion = '~18.2.0';
11
10
  exports.reactRefreshVersion = '~0.14.0';
12
- exports.reactDomVersion = '~18.2.0';
13
- exports.typesReactVersion = '~18.0.28';
14
- exports.typesReactDomVersion = '~18.0.10';
15
11
  exports.nestjsCommonVersion = '~9.0.0';
16
12
  exports.nestjsCoreVersion = '~9.0.0';
17
13
  exports.nestjsPlatformExpressVersion = '~9.0.0';