@nx/web 17.2.0-beta.1 → 17.2.0-beta.11
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 +4 -4
- package/src/executors/file-server/schema.d.ts +3 -3
- package/src/generators/application/application.js +70 -42
- package/src/generators/application/files/app-webpack/webpack.config.js__tmpl__ +35 -5
- package/src/migrations/update-15-9-1/add-dropped-dependencies.js +2 -2
- package/src/utils/has-webpack-plugin.d.ts +2 -0
- package/src/utils/has-webpack-plugin.js +11 -0
- package/src/utils/wait-for-port-open.js +10 -2
- package/src/generators/application/files/app-webpack/src/environments/environment.prod.ts__tmpl__ +0 -3
- package/src/generators/application/files/app-webpack/src/environments/environment.ts__tmpl__ +0 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/web",
|
|
3
|
-
"version": "17.2.0-beta.
|
|
3
|
+
"version": "17.2.0-beta.11",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The Nx Plugin for Web Components contains generators for managing Web Component applications and libraries within an Nx workspace. It provides:\n\n\n- Integration with libraries such as Jest, Cypress, and Storybook.\n\n- Scaffolding for creating buildable libraries that can be published to npm.\n\n- Utilities for automatic workspace refactoring.",
|
|
6
6
|
"repository": {
|
|
@@ -34,9 +34,9 @@
|
|
|
34
34
|
"detect-port": "^1.5.1",
|
|
35
35
|
"http-server": "^14.1.0",
|
|
36
36
|
"tslib": "^2.3.0",
|
|
37
|
-
"@nx/devkit": "17.2.0-beta.
|
|
38
|
-
"@nx/js": "17.2.0-beta.
|
|
39
|
-
"@nrwl/web": "17.2.0-beta.
|
|
37
|
+
"@nx/devkit": "17.2.0-beta.11",
|
|
38
|
+
"@nx/js": "17.2.0-beta.11",
|
|
39
|
+
"@nrwl/web": "17.2.0-beta.11"
|
|
40
40
|
},
|
|
41
41
|
"publishConfig": {
|
|
42
42
|
"access": "public"
|
|
@@ -9,16 +9,42 @@ const path_1 = require("path");
|
|
|
9
9
|
const versions_2 = require("../../utils/versions");
|
|
10
10
|
const init_1 = require("../init/init");
|
|
11
11
|
const get_npm_scope_1 = require("@nx/js/src/utils/package-json/get-npm-scope");
|
|
12
|
+
const has_webpack_plugin_1 = require("../../utils/has-webpack-plugin");
|
|
12
13
|
function createApplicationFiles(tree, options) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
if (options.bundler === 'vite') {
|
|
15
|
+
(0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, './files/app-vite'), options.appProjectRoot, {
|
|
16
|
+
...options,
|
|
17
|
+
...(0, devkit_1.names)(options.name),
|
|
18
|
+
tmpl: '',
|
|
19
|
+
offsetFromRoot: (0, devkit_1.offsetFromRoot)(options.appProjectRoot),
|
|
20
|
+
rootTsConfigPath: (0, js_1.getRelativePathToRootTsConfig)(tree, options.appProjectRoot),
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
(0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, './files/app-webpack'), options.appProjectRoot, {
|
|
25
|
+
...options,
|
|
26
|
+
...(0, devkit_1.names)(options.name),
|
|
27
|
+
tmpl: '',
|
|
28
|
+
offsetFromRoot: (0, devkit_1.offsetFromRoot)(options.appProjectRoot),
|
|
29
|
+
rootTsConfigPath: (0, js_1.getRelativePathToRootTsConfig)(tree, options.appProjectRoot),
|
|
30
|
+
webpackPluginOptions: (0, has_webpack_plugin_1.hasWebpackPlugin)(tree)
|
|
31
|
+
? {
|
|
32
|
+
target: 'web',
|
|
33
|
+
outputPath: (0, devkit_1.joinPathFragments)('dist', options.appProjectRoot != '.'
|
|
34
|
+
? options.appProjectRoot
|
|
35
|
+
: options.projectName),
|
|
36
|
+
tsConfig: './tsconfig.app.json',
|
|
37
|
+
main: './src/main.ts',
|
|
38
|
+
assets: ['./src/favicon.ico', './src/assets'],
|
|
39
|
+
index: './src/index.html',
|
|
40
|
+
baseHref: '/',
|
|
41
|
+
styles: [`./src/styles.${options.style}`],
|
|
42
|
+
}
|
|
43
|
+
: null,
|
|
44
|
+
});
|
|
45
|
+
if (options.unitTestRunner === 'none') {
|
|
46
|
+
tree.delete((0, path_1.join)(options.appProjectRoot, './src/app/app.element.spec.ts'));
|
|
47
|
+
}
|
|
22
48
|
}
|
|
23
49
|
}
|
|
24
50
|
async function setupBundler(tree, options) {
|
|
@@ -31,6 +57,7 @@ async function setupBundler(tree, options) {
|
|
|
31
57
|
if (options.bundler === 'webpack') {
|
|
32
58
|
const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/webpack', versions_2.nxVersion);
|
|
33
59
|
await configurationGenerator(tree, {
|
|
60
|
+
target: 'web',
|
|
34
61
|
project: options.projectName,
|
|
35
62
|
main,
|
|
36
63
|
tsConfig,
|
|
@@ -40,35 +67,37 @@ async function setupBundler(tree, options) {
|
|
|
40
67
|
skipFormat: true,
|
|
41
68
|
});
|
|
42
69
|
const project = (0, devkit_1.readProjectConfiguration)(tree, options.projectName);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
70
|
+
if (project.targets.build) {
|
|
71
|
+
const prodConfig = project.targets.build.configurations.production;
|
|
72
|
+
const buildOptions = project.targets.build.options;
|
|
73
|
+
buildOptions.assets = assets;
|
|
74
|
+
buildOptions.index = (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/index.html');
|
|
75
|
+
buildOptions.baseHref = '/';
|
|
76
|
+
buildOptions.styles = [
|
|
77
|
+
(0, devkit_1.joinPathFragments)(options.appProjectRoot, `src/styles.${options.style}`),
|
|
78
|
+
];
|
|
79
|
+
// We can delete that, because this projest is an application
|
|
80
|
+
// and applications have a .babelrc file in their root dir.
|
|
81
|
+
// So Nx will find it and use it
|
|
82
|
+
delete buildOptions.babelUpwardRootMode;
|
|
83
|
+
buildOptions.scripts = [];
|
|
84
|
+
prodConfig.fileReplacements = [
|
|
85
|
+
{
|
|
86
|
+
replace: (0, devkit_1.joinPathFragments)(options.appProjectRoot, `src/environments/environment.ts`),
|
|
87
|
+
with: (0, devkit_1.joinPathFragments)(options.appProjectRoot, `src/environments/environment.prod.ts`),
|
|
88
|
+
},
|
|
89
|
+
];
|
|
90
|
+
prodConfig.optimization = true;
|
|
91
|
+
prodConfig.outputHashing = 'all';
|
|
92
|
+
prodConfig.sourceMap = false;
|
|
93
|
+
prodConfig.namedChunks = false;
|
|
94
|
+
prodConfig.extractLicenses = true;
|
|
95
|
+
prodConfig.vendorChunk = false;
|
|
96
|
+
(0, devkit_1.updateProjectConfiguration)(tree, options.projectName, project);
|
|
97
|
+
}
|
|
98
|
+
// TODO(jack): Flush this out... no bundler should be possible for web but the experience isn't holistic due to missing features (e.g. writing index.html).
|
|
69
99
|
}
|
|
70
100
|
else if (options.bundler === 'none') {
|
|
71
|
-
// TODO(jack): Flush this out... no bundler should be possible for web but the experience isn't holistic due to missing features (e.g. writing index.html).
|
|
72
101
|
const project = (0, devkit_1.readProjectConfiguration)(tree, options.projectName);
|
|
73
102
|
project.targets.build = {
|
|
74
103
|
executor: `@nx/js:${options.compiler}`,
|
|
@@ -77,7 +106,6 @@ async function setupBundler(tree, options) {
|
|
|
77
106
|
main,
|
|
78
107
|
outputPath: (0, devkit_1.joinPathFragments)('dist', options.appProjectRoot),
|
|
79
108
|
tsConfig,
|
|
80
|
-
assets,
|
|
81
109
|
},
|
|
82
110
|
};
|
|
83
111
|
(0, devkit_1.updateProjectConfiguration)(tree, options.projectName, project);
|
|
@@ -95,9 +123,6 @@ async function addProject(tree, options) {
|
|
|
95
123
|
tags: options.parsedTags,
|
|
96
124
|
targets,
|
|
97
125
|
}, options.standaloneConfig);
|
|
98
|
-
if (options.bundler !== 'vite') {
|
|
99
|
-
await setupBundler(tree, options);
|
|
100
|
-
}
|
|
101
126
|
}
|
|
102
127
|
function setDefaults(tree, options) {
|
|
103
128
|
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
@@ -126,8 +151,11 @@ async function applicationGeneratorInternal(host, schema) {
|
|
|
126
151
|
skipFormat: true,
|
|
127
152
|
});
|
|
128
153
|
tasks.push(webTask);
|
|
129
|
-
createApplicationFiles(host, options);
|
|
130
154
|
await addProject(host, options);
|
|
155
|
+
if (options.bundler !== 'vite') {
|
|
156
|
+
await setupBundler(host, options);
|
|
157
|
+
}
|
|
158
|
+
createApplicationFiles(host, options);
|
|
131
159
|
if (options.bundler === 'vite') {
|
|
132
160
|
const { viteConfigurationGenerator, createOrEditViteConfig } = (0, devkit_1.ensurePackage)('@nx/vite', versions_2.nxVersion);
|
|
133
161
|
// We recommend users use `import.meta.env.MODE` and other variables in their code to differentiate between production and development.
|
|
@@ -181,7 +209,6 @@ async function applicationGeneratorInternal(host, schema) {
|
|
|
181
209
|
(0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
|
|
182
210
|
],
|
|
183
211
|
unitTestRunner: options.unitTestRunner,
|
|
184
|
-
eslintFilePatterns: [`${options.appProjectRoot}/**/*.ts`],
|
|
185
212
|
skipFormat: true,
|
|
186
213
|
setParserOptionsProject: options.setParserOptionsProject,
|
|
187
214
|
});
|
|
@@ -201,6 +228,7 @@ async function applicationGeneratorInternal(host, schema) {
|
|
|
201
228
|
...options,
|
|
202
229
|
project: options.e2eProjectName,
|
|
203
230
|
devServerTarget: `${options.projectName}:serve`,
|
|
231
|
+
baseUrl: 'http://localhost:4200',
|
|
204
232
|
directory: 'src',
|
|
205
233
|
skipFormat: true,
|
|
206
234
|
});
|
|
@@ -1,8 +1,38 @@
|
|
|
1
|
+
<% if (webpackPluginOptions) { %>
|
|
2
|
+
const { NxWebpackPlugin } = require('@nx/webpack');
|
|
3
|
+
const { join } = require('path');
|
|
4
|
+
|
|
5
|
+
module.exports = {
|
|
6
|
+
output: {
|
|
7
|
+
path: join(__dirname, '<%= offsetFromRoot %><%= webpackPluginOptions.outputPath %>'),
|
|
8
|
+
},
|
|
9
|
+
devServer: {
|
|
10
|
+
port: 4200
|
|
11
|
+
},
|
|
12
|
+
plugins: [
|
|
13
|
+
new NxWebpackPlugin({
|
|
14
|
+
tsConfig: '<%= webpackPluginOptions.tsConfig %>',
|
|
15
|
+
main: '<%= webpackPluginOptions.main %>',
|
|
16
|
+
index: '<%= webpackPluginOptions.index %>',
|
|
17
|
+
baseHref: '<%= webpackPluginOptions.baseHref %>',
|
|
18
|
+
assets: <%- JSON.stringify(webpackPluginOptions.assets) %>,
|
|
19
|
+
styles: <%- JSON.stringify(webpackPluginOptions.styles) %>,
|
|
20
|
+
outputHashing: process.env['NODE_ENV'] === 'production' ? 'all' : 'none',
|
|
21
|
+
optimization: process.env['NODE_ENV'] === 'production',
|
|
22
|
+
})
|
|
23
|
+
],
|
|
24
|
+
};
|
|
25
|
+
<% } else { %>
|
|
1
26
|
const { composePlugins, withNx, withWeb } = require('@nx/webpack');
|
|
2
27
|
|
|
3
28
|
// Nx plugins for webpack.
|
|
4
|
-
module.exports = composePlugins(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
29
|
+
module.exports = composePlugins(
|
|
30
|
+
withNx(),
|
|
31
|
+
withWeb(),
|
|
32
|
+
(config) => {
|
|
33
|
+
// Update the webpack config as needed here.
|
|
34
|
+
// e.g. `config.plugins.push(new MyPlugin())`
|
|
35
|
+
return config;
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
<% } %>
|
|
@@ -13,7 +13,7 @@ async function addDroppedDependencies(tree) {
|
|
|
13
13
|
for (const [_, projectConfiguration] of projects) {
|
|
14
14
|
for (const [_, targetConfiguration] of Object.entries(projectConfiguration.targets ?? {})) {
|
|
15
15
|
for (const droppedDependency of droppedDependencies) {
|
|
16
|
-
if (targetConfiguration
|
|
16
|
+
if (targetConfiguration?.['executor']?.startsWith(droppedDependency + ':')) {
|
|
17
17
|
devDependencies[droppedDependency] = devkit_1.NX_VERSION;
|
|
18
18
|
}
|
|
19
19
|
}
|
|
@@ -22,7 +22,7 @@ async function addDroppedDependencies(tree) {
|
|
|
22
22
|
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
23
23
|
for (const [_, targetConfiguration] of Object.entries(nxJson?.targetDefaults ?? {})) {
|
|
24
24
|
for (const droppedDependency of droppedDependencies) {
|
|
25
|
-
if (targetConfiguration
|
|
25
|
+
if (targetConfiguration?.['executor']?.startsWith(droppedDependency + ':')) {
|
|
26
26
|
devDependencies[droppedDependency] = devkit_1.NX_VERSION;
|
|
27
27
|
}
|
|
28
28
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hasWebpackPlugin = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
function hasWebpackPlugin(tree) {
|
|
6
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
7
|
+
return !!nxJson.plugins?.some((p) => typeof p === 'string'
|
|
8
|
+
? p === '@nx/webpack/plugin'
|
|
9
|
+
: p.plugin === '@nx/webpack/plugin');
|
|
10
|
+
}
|
|
11
|
+
exports.hasWebpackPlugin = hasWebpackPlugin;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.waitForPortOpen = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
4
5
|
const net = require("net");
|
|
5
6
|
function waitForPortOpen(port, options = {}) {
|
|
6
|
-
const
|
|
7
|
+
const host = options.host ?? '127.0.0.1';
|
|
8
|
+
const allowedErrorCodes = ['ECONNREFUSED', 'ECONNRESET', 'ETIMEDOUT'];
|
|
7
9
|
return new Promise((resolve, reject) => {
|
|
8
10
|
const checkPort = (retries = options.retries ?? 120) => {
|
|
9
11
|
const client = new net.Socket();
|
|
@@ -20,6 +22,9 @@ function waitForPortOpen(port, options = {}) {
|
|
|
20
22
|
});
|
|
21
23
|
client.once('error', (err) => {
|
|
22
24
|
if (retries === 0 || !allowedErrorCodes.includes(err['code'])) {
|
|
25
|
+
if (process.env['NX_VERBOSE_LOGGING'] === 'true') {
|
|
26
|
+
devkit_1.logger.info(`Error connecting on ${host}:${port}: ${err['code'] || err}`);
|
|
27
|
+
}
|
|
23
28
|
cleanupClient();
|
|
24
29
|
reject(err);
|
|
25
30
|
}
|
|
@@ -29,7 +34,10 @@ function waitForPortOpen(port, options = {}) {
|
|
|
29
34
|
});
|
|
30
35
|
// Node will use IPv6 if it is available, but this can cause issues if the server is only listening on IPv4.
|
|
31
36
|
// Hard-coding to look on 127.0.0.1 to avoid using the IPv6 loopback address "::1".
|
|
32
|
-
|
|
37
|
+
if (process.env['NX_VERBOSE_LOGGING'] === 'true') {
|
|
38
|
+
devkit_1.logger.info(`Connecting on ${host}:${port}`);
|
|
39
|
+
}
|
|
40
|
+
client.connect({ port, host });
|
|
33
41
|
};
|
|
34
42
|
checkPort();
|
|
35
43
|
});
|