@nx/web 17.2.0-beta.8 → 17.2.0-beta.9
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 +68 -41
- package/src/generators/application/files/app-webpack/webpack.config.js__tmpl__ +35 -5
- package/src/utils/has-webpack-plugin.d.ts +2 -0
- package/src/utils/has-webpack-plugin.js +11 -0
- 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.9",
|
|
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.9",
|
|
38
|
+
"@nx/js": "17.2.0-beta.9",
|
|
39
|
+
"@nrwl/web": "17.2.0-beta.9"
|
|
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) {
|
|
@@ -41,35 +67,37 @@ async function setupBundler(tree, options) {
|
|
|
41
67
|
skipFormat: true,
|
|
42
68
|
});
|
|
43
69
|
const project = (0, devkit_1.readProjectConfiguration)(tree, options.projectName);
|
|
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
|
-
|
|
69
|
-
|
|
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).
|
|
70
99
|
}
|
|
71
100
|
else if (options.bundler === 'none') {
|
|
72
|
-
// 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).
|
|
73
101
|
const project = (0, devkit_1.readProjectConfiguration)(tree, options.projectName);
|
|
74
102
|
project.targets.build = {
|
|
75
103
|
executor: `@nx/js:${options.compiler}`,
|
|
@@ -78,7 +106,6 @@ async function setupBundler(tree, options) {
|
|
|
78
106
|
main,
|
|
79
107
|
outputPath: (0, devkit_1.joinPathFragments)('dist', options.appProjectRoot),
|
|
80
108
|
tsConfig,
|
|
81
|
-
assets,
|
|
82
109
|
},
|
|
83
110
|
};
|
|
84
111
|
(0, devkit_1.updateProjectConfiguration)(tree, options.projectName, project);
|
|
@@ -96,9 +123,6 @@ async function addProject(tree, options) {
|
|
|
96
123
|
tags: options.parsedTags,
|
|
97
124
|
targets,
|
|
98
125
|
}, options.standaloneConfig);
|
|
99
|
-
if (options.bundler !== 'vite') {
|
|
100
|
-
await setupBundler(tree, options);
|
|
101
|
-
}
|
|
102
126
|
}
|
|
103
127
|
function setDefaults(tree, options) {
|
|
104
128
|
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
@@ -127,8 +151,11 @@ async function applicationGeneratorInternal(host, schema) {
|
|
|
127
151
|
skipFormat: true,
|
|
128
152
|
});
|
|
129
153
|
tasks.push(webTask);
|
|
130
|
-
createApplicationFiles(host, options);
|
|
131
154
|
await addProject(host, options);
|
|
155
|
+
if (options.bundler !== 'vite') {
|
|
156
|
+
await setupBundler(host, options);
|
|
157
|
+
}
|
|
158
|
+
createApplicationFiles(host, options);
|
|
132
159
|
if (options.bundler === 'vite') {
|
|
133
160
|
const { viteConfigurationGenerator, createOrEditViteConfig } = (0, devkit_1.ensurePackage)('@nx/vite', versions_2.nxVersion);
|
|
134
161
|
// We recommend users use `import.meta.env.MODE` and other variables in their code to differentiate between production and development.
|
|
@@ -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
|
+
<% } %>
|
|
@@ -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;
|