@nx/rspack 20.4.0-beta.1 → 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 +6 -6
- package/src/executors/ssr-dev-server/ssr-dev-server.impl.js +2 -2
- package/src/generators/configuration/configuration.js +2 -1
- package/src/plugins/plugin.js +7 -2
- package/src/utils/generator-utils.js +19 -1
- package/src/utils/read-rspack-options.d.ts +5 -4
- package/src/utils/read-rspack-options.js +65 -36
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.
|
|
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.
|
|
28
|
-
"@nx/devkit": "20.4.0-beta.
|
|
29
|
-
"@nx/web": "20.4.0-beta.
|
|
30
|
-
"@nx/module-federation": "20.4.0-beta.
|
|
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
|
|
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(`[ ${
|
|
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
|
package/src/plugins/plugin.js
CHANGED
|
@@ -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
|
|
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
|
|
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 (
|
|
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.
|
|
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.
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
77
|
+
const resolved = await resolveConfig(rspackConfig);
|
|
78
|
+
configs.push(...flattenConfigs(resolved));
|
|
50
79
|
}
|
|
51
|
-
return
|
|
80
|
+
return configs;
|
|
52
81
|
}
|