@nx/webpack 20.7.0 → 20.7.1
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/migrations.json +13 -0
- package/package.json +5 -5
- package/src/generators/convert-to-inferred/utils/serve-post-target-transformer.js +4 -1
- package/src/plugins/nx-webpack-plugin/lib/apply-base-config.js +31 -3
- package/src/plugins/nx-webpack-plugin/lib/utils.d.ts +7 -0
- package/src/plugins/nx-webpack-plugin/lib/utils.js +48 -0
- package/src/plugins/nx-webpack-plugin/nx-app-webpack-plugin-options.d.ts +1 -0
- package/src/plugins/nx-webpack-plugin/nx-app-webpack-plugin.js +4 -0
package/migrations.json
CHANGED
|
@@ -44,6 +44,19 @@
|
|
|
44
44
|
"alwaysAddToPackageJson": false
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
+
},
|
|
48
|
+
"20.7.1": {
|
|
49
|
+
"version": "20.7.1-beta.0",
|
|
50
|
+
"packages": {
|
|
51
|
+
"webpack": {
|
|
52
|
+
"version": "^5.98.0",
|
|
53
|
+
"alwaysAddToPackageJson": false
|
|
54
|
+
},
|
|
55
|
+
"webpack-dev-server": {
|
|
56
|
+
"version": "^5.2.1",
|
|
57
|
+
"alwaysAddToPackageJson": false
|
|
58
|
+
}
|
|
59
|
+
}
|
|
47
60
|
}
|
|
48
61
|
}
|
|
49
62
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/webpack",
|
|
3
|
-
"version": "20.7.
|
|
3
|
+
"version": "20.7.1",
|
|
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": {
|
|
@@ -62,12 +62,12 @@
|
|
|
62
62
|
"ts-loader": "^9.3.1",
|
|
63
63
|
"tsconfig-paths-webpack-plugin": "4.0.0",
|
|
64
64
|
"tslib": "^2.3.0",
|
|
65
|
-
"webpack": "^5.
|
|
66
|
-
"webpack-dev-server": "^5.
|
|
65
|
+
"webpack": "^5.98.0",
|
|
66
|
+
"webpack-dev-server": "^5.2.1",
|
|
67
67
|
"webpack-node-externals": "^3.0.0",
|
|
68
68
|
"webpack-subresource-integrity": "^5.1.0",
|
|
69
|
-
"@nx/devkit": "20.7.
|
|
70
|
-
"@nx/js": "20.7.
|
|
69
|
+
"@nx/devkit": "20.7.1",
|
|
70
|
+
"@nx/js": "20.7.1"
|
|
71
71
|
},
|
|
72
72
|
"publishConfig": {
|
|
73
73
|
"access": "public"
|
|
@@ -156,7 +156,10 @@ function extractDevServerOptions(options, context) {
|
|
|
156
156
|
return devServerOptions;
|
|
157
157
|
}
|
|
158
158
|
function applyDefaults(options, buildOptions) {
|
|
159
|
-
if (options
|
|
159
|
+
if (!options) {
|
|
160
|
+
options = {};
|
|
161
|
+
}
|
|
162
|
+
if (options?.port === undefined) {
|
|
160
163
|
options.port = 4200;
|
|
161
164
|
}
|
|
162
165
|
options.headers = { 'Access-Control-Allow-Origin': '*' };
|
|
@@ -15,6 +15,7 @@ const compiler_loaders_1 = require("./compiler-loaders");
|
|
|
15
15
|
const TerserPlugin = require("terser-webpack-plugin");
|
|
16
16
|
const nodeExternals = require("webpack-node-externals");
|
|
17
17
|
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
18
|
+
const utils_1 = require("./utils");
|
|
18
19
|
const IGNORED_WEBPACK_WARNINGS = [
|
|
19
20
|
/The comment file/i,
|
|
20
21
|
/could not find any license/i,
|
|
@@ -187,8 +188,11 @@ function applyNxDependentConfig(options, config, { useNormalizedEntry } = {}) {
|
|
|
187
188
|
if (options.useTsconfigPaths) {
|
|
188
189
|
plugins.push(new nx_tsconfig_paths_webpack_plugin_1.NxTsconfigPathsWebpackPlugin({ ...options, tsConfig }));
|
|
189
190
|
}
|
|
190
|
-
// New TS Solution already has a typecheck target
|
|
191
|
-
if (!options?.skipTypeChecking && !isUsingTsSolution)
|
|
191
|
+
// New TS Solution already has a typecheck target but allow it to run during serve
|
|
192
|
+
if ((!options?.skipTypeChecking && !isUsingTsSolution) ||
|
|
193
|
+
(isUsingTsSolution &&
|
|
194
|
+
options?.skipTypeChecking === false &&
|
|
195
|
+
process.env['WEBPACK_SERVE'])) {
|
|
192
196
|
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
|
|
193
197
|
plugins.push(new ForkTsCheckerWebpackPlugin({
|
|
194
198
|
typescript: {
|
|
@@ -275,7 +279,31 @@ function applyNxDependentConfig(options, config, { useNormalizedEntry } = {}) {
|
|
|
275
279
|
const externals = [];
|
|
276
280
|
if (options.target === 'node' && options.externalDependencies === 'all') {
|
|
277
281
|
const modulesDir = `${options.root}/node_modules`;
|
|
278
|
-
|
|
282
|
+
const graph = options.projectGraph;
|
|
283
|
+
const projectName = options.projectName;
|
|
284
|
+
const deps = graph?.dependencies?.[projectName] ?? [];
|
|
285
|
+
// Collect non-buildable TS project references so that they are bundled
|
|
286
|
+
// in the final output. This is needed for projects that are not buildable
|
|
287
|
+
// but are referenced by buildable projects. This is needed for the new TS
|
|
288
|
+
// solution setup.
|
|
289
|
+
const nonBuildableWorkspaceLibs = isUsingTsSolution
|
|
290
|
+
? deps
|
|
291
|
+
.filter((dep) => {
|
|
292
|
+
const node = graph.nodes?.[dep.target];
|
|
293
|
+
if (!node || node.type !== 'lib')
|
|
294
|
+
return false;
|
|
295
|
+
const hasBuildTarget = 'build' in (node.data?.targets ?? {});
|
|
296
|
+
if (hasBuildTarget) {
|
|
297
|
+
return false;
|
|
298
|
+
}
|
|
299
|
+
// If there is no build target we check the package exports to see if they reference
|
|
300
|
+
// source files
|
|
301
|
+
return !(0, utils_1.isBuildableLibrary)(node);
|
|
302
|
+
})
|
|
303
|
+
.map((dep) => graph.nodes?.[dep.target]?.data?.metadata?.js?.packageName)
|
|
304
|
+
.filter((name) => !!name)
|
|
305
|
+
: [];
|
|
306
|
+
externals.push(nodeExternals({ modulesDir, allowlist: nonBuildableWorkspaceLibs }));
|
|
279
307
|
}
|
|
280
308
|
else if (Array.isArray(options.externalDependencies)) {
|
|
281
309
|
externals.push(function (ctx, callback) {
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isBuildableLibrary = isBuildableLibrary;
|
|
4
|
+
function isSourceFile(path) {
|
|
5
|
+
return ['.ts', '.tsx', '.mts', '.cts'].some((ext) => path.endsWith(ext));
|
|
6
|
+
}
|
|
7
|
+
function isBuildableExportMap(packageExports) {
|
|
8
|
+
if (!packageExports || Object.keys(packageExports).length === 0) {
|
|
9
|
+
return false; // exports = {} → not buildable
|
|
10
|
+
}
|
|
11
|
+
const isCompiledExport = (value) => {
|
|
12
|
+
if (typeof value === 'string') {
|
|
13
|
+
return !isSourceFile(value);
|
|
14
|
+
}
|
|
15
|
+
if (typeof value === 'object' && value !== null) {
|
|
16
|
+
return Object.entries(value).some(([key, subValue]) => {
|
|
17
|
+
if (key === 'types' ||
|
|
18
|
+
key === 'development' ||
|
|
19
|
+
key === './package.json')
|
|
20
|
+
return false;
|
|
21
|
+
return typeof subValue === 'string' && !isSourceFile(subValue);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
25
|
+
};
|
|
26
|
+
if (packageExports['.']) {
|
|
27
|
+
return isCompiledExport(packageExports['.']);
|
|
28
|
+
}
|
|
29
|
+
return Object.entries(packageExports).some(([key, value]) => key !== '.' && isCompiledExport(value));
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Check if the library is buildable.
|
|
33
|
+
* @param node from the project graph
|
|
34
|
+
* @returns boolean
|
|
35
|
+
*/
|
|
36
|
+
function isBuildableLibrary(node) {
|
|
37
|
+
if (!node.data.metadata?.js) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
const { packageExports, packageMain } = node.data.metadata.js;
|
|
41
|
+
// if we have exports only check this else fallback to packageMain
|
|
42
|
+
if (packageExports) {
|
|
43
|
+
return isBuildableExportMap(packageExports);
|
|
44
|
+
}
|
|
45
|
+
return (typeof packageMain === 'string' &&
|
|
46
|
+
packageMain !== '' &&
|
|
47
|
+
!isSourceFile(packageMain));
|
|
48
|
+
}
|
|
@@ -73,6 +73,7 @@ export interface NxAppWebpackPluginOptions {
|
|
|
73
73
|
crossOrigin?: 'none' | 'anonymous' | 'use-credentials';
|
|
74
74
|
/**
|
|
75
75
|
* Delete the output path before building.
|
|
76
|
+
* @deprecated Use the `output.clean` option in Webpack. https://webpack.js.org/guides/output-management/#cleaning-up-the-dist-folder
|
|
76
77
|
*/
|
|
77
78
|
deleteOutputPath?: boolean;
|
|
78
79
|
/**
|
|
@@ -29,6 +29,10 @@ class NxAppWebpackPlugin {
|
|
|
29
29
|
if (typeof target === 'string') {
|
|
30
30
|
this.options.target = target;
|
|
31
31
|
}
|
|
32
|
+
// Prefer `clean` option from Webpack config over our own.
|
|
33
|
+
if (typeof compiler.options.output?.clean !== 'undefined') {
|
|
34
|
+
this.options.deleteOutputPath = false;
|
|
35
|
+
}
|
|
32
36
|
(0, apply_base_config_1.applyBaseConfig)(this.options, compiler.options, {
|
|
33
37
|
useNormalizedEntry: true,
|
|
34
38
|
});
|