@nx/webpack 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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/webpack",
|
|
3
|
-
"version": "20.4.0-beta.
|
|
3
|
+
"version": "20.4.0-beta.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The Nx Plugin for Webpack contains executors and generators that support building applications using Webpack.",
|
|
6
6
|
"repository": {
|
|
@@ -65,8 +65,8 @@
|
|
|
65
65
|
"webpack-dev-server": "^5.0.4",
|
|
66
66
|
"webpack-node-externals": "^3.0.0",
|
|
67
67
|
"webpack-subresource-integrity": "^5.1.0",
|
|
68
|
-
"@nx/devkit": "20.4.0-beta.
|
|
69
|
-
"@nx/js": "20.4.0-beta.
|
|
68
|
+
"@nx/devkit": "20.4.0-beta.2",
|
|
69
|
+
"@nx/js": "20.4.0-beta.2"
|
|
70
70
|
},
|
|
71
71
|
"publishConfig": {
|
|
72
72
|
"access": "public"
|
package/src/plugins/plugin.js
CHANGED
|
@@ -77,7 +77,12 @@ async function createWebpackTargets(configFilePath, projectRoot, options, contex
|
|
|
77
77
|
const namedInputs = (0, get_named_inputs_1.getNamedInputs)(projectRoot, context);
|
|
78
78
|
const webpackConfig = (0, resolve_user_defined_webpack_config_1.resolveUserDefinedWebpackConfig)((0, path_1.join)(context.workspaceRoot, configFilePath), (0, js_1.getRootTsConfigPath)(), true);
|
|
79
79
|
const webpackOptions = await (0, read_webpack_options_1.readWebpackOptions)(webpackConfig);
|
|
80
|
-
const
|
|
80
|
+
const outputs = [];
|
|
81
|
+
for (const config of webpackOptions) {
|
|
82
|
+
if (config.output?.path) {
|
|
83
|
+
outputs.push(normalizeOutputPath(config.output.path, projectRoot));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
81
86
|
const targets = {};
|
|
82
87
|
targets[options.buildTargetName] = {
|
|
83
88
|
command: `webpack-cli build`,
|
|
@@ -99,7 +104,7 @@ async function createWebpackTargets(configFilePath, projectRoot, options, contex
|
|
|
99
104
|
externalDependencies: ['webpack-cli'],
|
|
100
105
|
},
|
|
101
106
|
],
|
|
102
|
-
outputs
|
|
107
|
+
outputs,
|
|
103
108
|
metadata: {
|
|
104
109
|
technologies: ['webpack'],
|
|
105
110
|
description: 'Runs Webpack build',
|
|
@@ -3,8 +3,9 @@ import { Configuration } from 'webpack';
|
|
|
3
3
|
* Reads the webpack options from a give webpack configuration. The configuration can be:
|
|
4
4
|
* 1. A standard config object
|
|
5
5
|
* 2. A standard function that returns a config object (webpack.js.org/configuration/configuration-types/#exporting-a-function)
|
|
6
|
-
* 3.
|
|
6
|
+
* 3. An array of standard config objects (multi-configuration mode)
|
|
7
|
+
* 4. A Nx-specific composable function that takes Nx context, webpack config, and returns the config object.
|
|
7
8
|
*
|
|
8
9
|
* @param webpackConfig
|
|
9
10
|
*/
|
|
10
|
-
export declare function readWebpackOptions(webpackConfig: unknown): Promise<Configuration>;
|
|
11
|
+
export declare function readWebpackOptions(webpackConfig: unknown): Promise<Configuration[]>;
|
|
@@ -8,42 +8,70 @@ const devkit_internals_1 = require("nx/src/devkit-internals");
|
|
|
8
8
|
* Reads the webpack options from a give webpack configuration. The configuration can be:
|
|
9
9
|
* 1. A standard config object
|
|
10
10
|
* 2. A standard function that returns a config object (webpack.js.org/configuration/configuration-types/#exporting-a-function)
|
|
11
|
-
* 3.
|
|
11
|
+
* 3. An array of standard config objects (multi-configuration mode)
|
|
12
|
+
* 4. A Nx-specific composable function that takes Nx context, webpack config, and returns the config object.
|
|
12
13
|
*
|
|
13
14
|
* @param webpackConfig
|
|
14
15
|
*/
|
|
15
16
|
async function readWebpackOptions(webpackConfig) {
|
|
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
|
-
|
|
17
|
+
const configs = [];
|
|
18
|
+
const resolveConfig = async (config) => {
|
|
19
|
+
if ((0, config_1.isNxWebpackComposablePlugin)(config)) {
|
|
20
|
+
return await config({}, {
|
|
21
|
+
// These values are only used during build-time, so passing stubs here just to read out
|
|
22
|
+
options: {
|
|
23
|
+
root: devkit_1.workspaceRoot,
|
|
24
|
+
projectRoot: '',
|
|
25
|
+
sourceRoot: '',
|
|
26
|
+
outputFileName: undefined,
|
|
27
|
+
outputPath: undefined,
|
|
28
|
+
assets: undefined,
|
|
29
|
+
useTsconfigPaths: undefined,
|
|
30
|
+
},
|
|
31
|
+
context: {
|
|
32
|
+
root: devkit_1.workspaceRoot,
|
|
33
|
+
cwd: undefined,
|
|
34
|
+
isVerbose: false,
|
|
35
|
+
projectsConfigurations: null,
|
|
36
|
+
projectGraph: null,
|
|
37
|
+
nxJsonConfiguration: (0, devkit_internals_1.readNxJsonFromDisk)(devkit_1.workspaceRoot),
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
else if (typeof config === 'function') {
|
|
42
|
+
const resolved = await config({
|
|
43
|
+
production: true, // we want the production build options
|
|
44
|
+
}, {});
|
|
45
|
+
// If the resolved configuration is an array, resolve each configuration
|
|
46
|
+
return Array.isArray(resolved)
|
|
47
|
+
? await Promise.all(resolved.map(resolveConfig))
|
|
48
|
+
: resolved;
|
|
49
|
+
}
|
|
50
|
+
else if (Array.isArray(config)) {
|
|
51
|
+
// If the config passed is an array, resolve each configuration
|
|
52
|
+
const resolvedConfigs = await Promise.all(config.map(resolveConfig));
|
|
53
|
+
return resolvedConfigs.flat();
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
// Return plain configuration
|
|
57
|
+
return config;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
// Since configs can have nested arrays, we need to flatten them
|
|
61
|
+
const flattenConfigs = (resolvedConfigs) => {
|
|
62
|
+
return Array.isArray(resolvedConfigs)
|
|
63
|
+
? resolvedConfigs.flatMap((cfg) => flattenConfigs(cfg))
|
|
64
|
+
: [resolvedConfigs];
|
|
65
|
+
};
|
|
66
|
+
if (Array.isArray(webpackConfig)) {
|
|
67
|
+
for (const config of webpackConfig) {
|
|
68
|
+
const resolved = await resolveConfig(config);
|
|
69
|
+
configs.push(...flattenConfigs(resolved));
|
|
70
|
+
}
|
|
44
71
|
}
|
|
45
72
|
else {
|
|
46
|
-
|
|
73
|
+
const resolved = await resolveConfig(webpackConfig);
|
|
74
|
+
configs.push(...flattenConfigs(resolved));
|
|
47
75
|
}
|
|
48
|
-
return
|
|
76
|
+
return configs;
|
|
49
77
|
}
|