@nx/react 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 +6 -6
- package/plugins/component-testing/index.js +4 -8
- package/plugins/nx-react-webpack-plugin/lib/apply-react-config.js +2 -0
- package/plugins/storybook/index.js +1 -1
- package/plugins/with-react.d.ts +1 -2
- package/src/generators/application/application.js +8 -8
- package/src/generators/application/files/base-webpack/webpack.config.js__tmpl__ +46 -5
- package/src/generators/application/lib/add-e2e.js +7 -4
- package/src/generators/application/lib/add-project.d.ts +2 -1
- package/src/generators/application/lib/add-project.js +7 -4
- package/src/generators/application/lib/create-application-files.js +25 -1
- package/src/generators/library/lib/normalize-options.js +30 -5
- package/src/generators/setup-ssr/setup-ssr.js +0 -1
- package/src/module-federation/with-module-federation.d.ts +3 -3
- package/src/module-federation/with-module-federation.js +1 -1
- package/src/utils/has-webpack-plugin.d.ts +2 -0
- package/src/utils/has-webpack-plugin.js +11 -0
- package/src/generators/application/files/base-webpack/src/environments/environment.prod.ts__tmpl__ +0 -3
- package/src/generators/application/files/base-webpack/src/environments/environment.ts__tmpl__ +0 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/react",
|
|
3
|
-
"version": "17.2.0-beta.
|
|
3
|
+
"version": "17.2.0-beta.9",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The React plugin for Nx contains executors and generators for managing React applications and libraries within an Nx workspace. It provides:\n\n\n- Integration with libraries such as Jest, Cypress, and Storybook.\n\n- Generators for applications, libraries, components, hooks, and more.\n\n- Library build support for publishing packages to npm or other registries.\n\n- Utilities for automatic workspace refactoring.",
|
|
6
6
|
"repository": {
|
|
@@ -37,11 +37,11 @@
|
|
|
37
37
|
"file-loader": "^6.2.0",
|
|
38
38
|
"minimatch": "3.0.5",
|
|
39
39
|
"tslib": "^2.3.0",
|
|
40
|
-
"@nx/devkit": "17.2.0-beta.
|
|
41
|
-
"@nx/js": "17.2.0-beta.
|
|
42
|
-
"@nx/eslint": "17.2.0-beta.
|
|
43
|
-
"@nx/web": "17.2.0-beta.
|
|
44
|
-
"@nrwl/react": "17.2.0-beta.
|
|
40
|
+
"@nx/devkit": "17.2.0-beta.9",
|
|
41
|
+
"@nx/js": "17.2.0-beta.9",
|
|
42
|
+
"@nx/eslint": "17.2.0-beta.9",
|
|
43
|
+
"@nx/web": "17.2.0-beta.9",
|
|
44
|
+
"@nrwl/react": "17.2.0-beta.9"
|
|
45
45
|
},
|
|
46
46
|
"publishConfig": {
|
|
47
47
|
"access": "public"
|
|
@@ -140,24 +140,20 @@ function buildTargetWebpack(ctx, buildTarget, componentTestingProjectName) {
|
|
|
140
140
|
}
|
|
141
141
|
const context = (0, ct_helpers_1.createExecutorContext)(graph, buildableProjectConfig.targets, parsed.project, parsed.target, parsed.target);
|
|
142
142
|
const { normalizeOptions, } = require('@nx/webpack/src/executors/webpack/lib/normalize-options');
|
|
143
|
-
const {
|
|
144
|
-
const {
|
|
143
|
+
const { resolveUserDefinedWebpackConfig, } = require('@nx/webpack/src/utils/webpack/resolve-user-defined-webpack-config');
|
|
144
|
+
const { withNx } = require('@nx/webpack/src/utils/with-nx');
|
|
145
145
|
const options = normalizeOptions(withSchemaDefaults(parsed, context), devkit_1.workspaceRoot, buildableProjectConfig.root, buildableProjectConfig.sourceRoot);
|
|
146
146
|
let customWebpack;
|
|
147
147
|
if (options.webpackConfig) {
|
|
148
|
-
customWebpack =
|
|
148
|
+
customWebpack = resolveUserDefinedWebpackConfig(options.webpackConfig, options.tsConfig.startsWith(context.root)
|
|
149
149
|
? options.tsConfig
|
|
150
150
|
: (0, path_1.join)(context.root, options.tsConfig));
|
|
151
151
|
}
|
|
152
152
|
return async () => {
|
|
153
153
|
customWebpack = await customWebpack;
|
|
154
154
|
// TODO(jack): Once webpackConfig is always set in @nx/webpack:webpack, we no longer need this default.
|
|
155
|
-
const defaultWebpack =
|
|
155
|
+
const defaultWebpack = withNx({
|
|
156
156
|
...options,
|
|
157
|
-
// cypress will generate its own index.html from component-index.html
|
|
158
|
-
generateIndexHtml: false,
|
|
159
|
-
// causes issues with buildable libraries with ENOENT: no such file or directory, scandir error
|
|
160
|
-
extractLicenses: false,
|
|
161
157
|
root: devkit_1.workspaceRoot,
|
|
162
158
|
projectRoot: ctProjectConfig.root,
|
|
163
159
|
sourceRoot: ctProjectConfig.sourceRoot,
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.applyReactConfig = void 0;
|
|
4
4
|
function applyReactConfig(options, config = {}) {
|
|
5
|
+
if (!process.env['NX_TASK_TARGET_PROJECT'])
|
|
6
|
+
return;
|
|
5
7
|
addHotReload(config);
|
|
6
8
|
if (options.svgr !== false) {
|
|
7
9
|
removeSvgLoaderIfPresent(config);
|
|
@@ -140,7 +140,7 @@ const webpack = async (storybookWebpackConfig = {}, options) => {
|
|
|
140
140
|
};
|
|
141
141
|
// ESM build for modern browsers.
|
|
142
142
|
let baseWebpackConfig = {};
|
|
143
|
-
const configure = (0, config_1.composePluginsSync)(withNx({ skipTypeChecking: true }),
|
|
143
|
+
const configure = (0, config_1.composePluginsSync)(withNx({ target: 'web', skipTypeChecking: true }), (0, with_react_1.withReact)());
|
|
144
144
|
const finalConfig = configure(baseWebpackConfig, {
|
|
145
145
|
options: builderOptions,
|
|
146
146
|
context: { root: devkit_1.workspaceRoot }, // The context is not used here.
|
package/plugins/with-react.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Configuration } from 'webpack';
|
|
2
2
|
import type { NxWebpackExecutionContext, WithWebOptions } from '@nx/webpack';
|
|
3
|
-
interface WithReactOptions extends WithWebOptions {
|
|
3
|
+
export interface WithReactOptions extends WithWebOptions {
|
|
4
4
|
svgr?: false;
|
|
5
5
|
}
|
|
6
6
|
/**
|
|
@@ -8,4 +8,3 @@ interface WithReactOptions extends WithWebOptions {
|
|
|
8
8
|
* @returns {NxWebpackPlugin}
|
|
9
9
|
*/
|
|
10
10
|
export declare function withReact(pluginOptions?: WithReactOptions): (config: Configuration, context: NxWebpackExecutionContext) => Configuration;
|
|
11
|
-
export {};
|
|
@@ -64,6 +64,14 @@ async function applicationGeneratorInternal(host, schema) {
|
|
|
64
64
|
skipHelperLibs: options.bundler === 'vite',
|
|
65
65
|
});
|
|
66
66
|
tasks.push(initTask);
|
|
67
|
+
if (options.bundler === 'webpack') {
|
|
68
|
+
const { webpackInitGenerator } = (0, devkit_1.ensurePackage)('@nx/webpack', versions_1.nxVersion);
|
|
69
|
+
const webpackInitTask = await webpackInitGenerator(host, {
|
|
70
|
+
uiFramework: 'react',
|
|
71
|
+
skipFormat: true,
|
|
72
|
+
});
|
|
73
|
+
tasks.push(webpackInitTask);
|
|
74
|
+
}
|
|
67
75
|
if (!options.rootProject) {
|
|
68
76
|
(0, create_ts_config_1.extractTsConfigBase)(host);
|
|
69
77
|
}
|
|
@@ -104,14 +112,6 @@ async function applicationGeneratorInternal(host, schema) {
|
|
|
104
112
|
plugins: ['react()'],
|
|
105
113
|
}, false);
|
|
106
114
|
}
|
|
107
|
-
else if (options.bundler === 'webpack') {
|
|
108
|
-
const { webpackInitGenerator } = (0, devkit_1.ensurePackage)('@nx/webpack', versions_1.nxVersion);
|
|
109
|
-
const webpackInitTask = await webpackInitGenerator(host, {
|
|
110
|
-
uiFramework: 'react',
|
|
111
|
-
skipFormat: true,
|
|
112
|
-
});
|
|
113
|
-
tasks.push(webpackInitTask);
|
|
114
|
-
}
|
|
115
115
|
else if (options.bundler === 'rspack') {
|
|
116
116
|
const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/rspack', versions_1.nxRspackVersion);
|
|
117
117
|
const rspackTask = await configurationGenerator(host, {
|
|
@@ -1,9 +1,50 @@
|
|
|
1
|
+
<% if (webpackPluginOptions) { %>
|
|
2
|
+
const { NxWebpackPlugin } = require('@nx/webpack');
|
|
3
|
+
const { NxReactWebpackPlugin } = require('@nx/react');
|
|
4
|
+
const { join } = require('path');
|
|
5
|
+
|
|
6
|
+
module.exports = {
|
|
7
|
+
output: {
|
|
8
|
+
path: join(__dirname, '<%= offsetFromRoot %><%= webpackPluginOptions.outputPath %>'),
|
|
9
|
+
},
|
|
10
|
+
devServer: {
|
|
11
|
+
port: 4200
|
|
12
|
+
},
|
|
13
|
+
plugins: [
|
|
14
|
+
new NxWebpackPlugin({
|
|
15
|
+
tsConfig: '<%= webpackPluginOptions.tsConfig %>',
|
|
16
|
+
compiler: '<%= webpackPluginOptions.compiler %>',
|
|
17
|
+
main: '<%= webpackPluginOptions.main %>',
|
|
18
|
+
index: '<%= webpackPluginOptions.index %>',
|
|
19
|
+
baseHref: '<%= webpackPluginOptions.baseHref %>',
|
|
20
|
+
assets: <%- JSON.stringify(webpackPluginOptions.assets) %>,
|
|
21
|
+
styles: <%- JSON.stringify(webpackPluginOptions.styles) %>,
|
|
22
|
+
outputHashing: process.env['NODE_ENV'] === 'production' ? 'all' : 'none',
|
|
23
|
+
optimization: process.env['NODE_ENV'] === 'production',
|
|
24
|
+
}),
|
|
25
|
+
new NxReactWebpackPlugin({
|
|
26
|
+
// Uncomment this line if you don't want to use SVGR
|
|
27
|
+
// See: https://react-svgr.com/
|
|
28
|
+
// svgr: false
|
|
29
|
+
}),
|
|
30
|
+
],
|
|
31
|
+
};
|
|
32
|
+
<% } else { %>
|
|
1
33
|
const { composePlugins, withNx } = require('@nx/webpack');
|
|
2
34
|
const { withReact } = require('@nx/react');
|
|
3
35
|
|
|
4
36
|
// Nx plugins for webpack.
|
|
5
|
-
module.exports = composePlugins(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
37
|
+
module.exports = composePlugins(
|
|
38
|
+
withNx(),
|
|
39
|
+
withReact({
|
|
40
|
+
// Uncomment this line if you don't want to use SVGR
|
|
41
|
+
// See: https://react-svgr.com/
|
|
42
|
+
// svgr: false
|
|
43
|
+
}),
|
|
44
|
+
(config) => {
|
|
45
|
+
// Update the webpack config as needed here.
|
|
46
|
+
// e.g. `config.plugins.push(new MyPlugin())`
|
|
47
|
+
return config;
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
<% } %>
|
|
@@ -4,13 +4,16 @@ exports.addE2e = void 0;
|
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const web_1 = require("@nx/web");
|
|
6
6
|
const versions_1 = require("../../../utils/versions");
|
|
7
|
+
const has_webpack_plugin_1 = require("../../../utils/has-webpack-plugin");
|
|
7
8
|
async function addE2e(tree, options) {
|
|
8
9
|
switch (options.e2eTestRunner) {
|
|
9
10
|
case 'cypress': {
|
|
10
|
-
(0,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
if (!(0, has_webpack_plugin_1.hasWebpackPlugin)(tree)) {
|
|
12
|
+
(0, web_1.webStaticServeGenerator)(tree, {
|
|
13
|
+
buildTarget: `${options.projectName}:build`,
|
|
14
|
+
targetName: 'serve-static',
|
|
15
|
+
});
|
|
16
|
+
}
|
|
14
17
|
const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/cypress', versions_1.nxVersion);
|
|
15
18
|
(0, devkit_1.addProjectConfiguration)(tree, options.e2eProjectName, {
|
|
16
19
|
projectType: 'application',
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { NormalizedSchema } from '../schema';
|
|
2
|
-
|
|
2
|
+
import { Tree } from '@nx/devkit';
|
|
3
|
+
export declare function addProject(host: Tree, options: NormalizedSchema): void;
|
|
3
4
|
export declare function maybeJs(options: NormalizedSchema, path: string): string;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.maybeJs = exports.addProject = void 0;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const has_webpack_plugin_1 = require("../../../utils/has-webpack-plugin");
|
|
5
6
|
function addProject(host, options) {
|
|
6
7
|
const project = {
|
|
7
8
|
root: options.appProjectRoot,
|
|
@@ -11,10 +12,12 @@ function addProject(host, options) {
|
|
|
11
12
|
tags: options.parsedTags,
|
|
12
13
|
};
|
|
13
14
|
if (options.bundler === 'webpack') {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
if (!(0, has_webpack_plugin_1.hasWebpackPlugin)(host)) {
|
|
16
|
+
project.targets = {
|
|
17
|
+
build: createBuildTarget(options),
|
|
18
|
+
serve: createServeTarget(options),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
18
21
|
}
|
|
19
22
|
(0, devkit_1.addProjectConfiguration)(host, options.projectName, {
|
|
20
23
|
...project,
|
|
@@ -7,6 +7,8 @@ const path_1 = require("path");
|
|
|
7
7
|
const create_ts_config_1 = require("../../../utils/create-ts-config");
|
|
8
8
|
const get_in_source_vitest_tests_template_1 = require("../../../utils/get-in-source-vitest-tests-template");
|
|
9
9
|
const get_app_tests_1 = require("./get-app-tests");
|
|
10
|
+
const add_project_1 = require("./add-project");
|
|
11
|
+
const has_webpack_plugin_1 = require("../../../utils/has-webpack-plugin");
|
|
10
12
|
function createApplicationFiles(host, options) {
|
|
11
13
|
let styleSolutionSpecificAppFiles;
|
|
12
14
|
if (options.styledModule && options.style !== 'styled-jsx') {
|
|
@@ -38,7 +40,12 @@ function createApplicationFiles(host, options) {
|
|
|
38
40
|
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/base-vite'), options.appProjectRoot, templateVariables);
|
|
39
41
|
}
|
|
40
42
|
else if (options.bundler === 'webpack') {
|
|
41
|
-
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/base-webpack'), options.appProjectRoot,
|
|
43
|
+
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/base-webpack'), options.appProjectRoot, {
|
|
44
|
+
...templateVariables,
|
|
45
|
+
webpackPluginOptions: (0, has_webpack_plugin_1.hasWebpackPlugin)(host)
|
|
46
|
+
? createNxWebpackPluginOptions(options)
|
|
47
|
+
: null,
|
|
48
|
+
});
|
|
42
49
|
if (options.compiler === 'babel') {
|
|
43
50
|
(0, devkit_1.writeJson)(host, `${options.appProjectRoot}/.babelrc`, {
|
|
44
51
|
presets: [
|
|
@@ -112,3 +119,20 @@ function createApplicationFiles(host, options) {
|
|
|
112
119
|
(0, create_ts_config_1.createTsConfig)(host, options.appProjectRoot, 'app', options, relativePathToRootTsConfig);
|
|
113
120
|
}
|
|
114
121
|
exports.createApplicationFiles = createApplicationFiles;
|
|
122
|
+
function createNxWebpackPluginOptions(options) {
|
|
123
|
+
return {
|
|
124
|
+
target: 'web',
|
|
125
|
+
compiler: options.compiler ?? 'babel',
|
|
126
|
+
outputPath: (0, devkit_1.joinPathFragments)('dist', options.appProjectRoot != '.'
|
|
127
|
+
? options.appProjectRoot
|
|
128
|
+
: options.projectName),
|
|
129
|
+
index: './src/index.html',
|
|
130
|
+
baseHref: '/',
|
|
131
|
+
main: (0, add_project_1.maybeJs)(options, `./src/main.tsx`),
|
|
132
|
+
tsConfig: './tsconfig.app.json',
|
|
133
|
+
assets: ['./src/favicon.ico', './src/assets'],
|
|
134
|
+
styles: options.styledModule || !options.hasStyles
|
|
135
|
+
? []
|
|
136
|
+
: [`./src/styles.${options.style}`],
|
|
137
|
+
};
|
|
138
|
+
}
|
|
@@ -49,11 +49,12 @@ async function normalizeOptions(host, options) {
|
|
|
49
49
|
if (appProjectConfig.projectType !== 'application') {
|
|
50
50
|
throw new Error(`appProject expected type of "application" but got "${appProjectConfig.projectType}"`);
|
|
51
51
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
52
|
+
normalized.appMain =
|
|
53
|
+
appProjectConfig.targets.build.options.main ??
|
|
54
|
+
findMainEntry(host, appProjectConfig.root);
|
|
55
|
+
normalized.appSourceRoot = (0, devkit_1.normalizePath)(appProjectConfig.sourceRoot);
|
|
56
|
+
// TODO(jack): We should use appEntryFile instead of appProject so users can directly set it rather than us inferring it.
|
|
57
|
+
if (!normalized.appMain) {
|
|
57
58
|
throw new Error(`Could not locate project main for ${options.appProject}`);
|
|
58
59
|
}
|
|
59
60
|
}
|
|
@@ -61,3 +62,27 @@ async function normalizeOptions(host, options) {
|
|
|
61
62
|
return normalized;
|
|
62
63
|
}
|
|
63
64
|
exports.normalizeOptions = normalizeOptions;
|
|
65
|
+
function findMainEntry(tree, projectRoot) {
|
|
66
|
+
const mainFiles = [
|
|
67
|
+
// These are the main files we generate with.
|
|
68
|
+
'src/main.ts',
|
|
69
|
+
'src/main.tsx',
|
|
70
|
+
'src/main.js',
|
|
71
|
+
'src/main.jsx',
|
|
72
|
+
// Other options just in case
|
|
73
|
+
'src/index.ts',
|
|
74
|
+
'src/index.tsx',
|
|
75
|
+
'src/index.js',
|
|
76
|
+
'src/index.jsx',
|
|
77
|
+
'main.ts',
|
|
78
|
+
'main.tsx',
|
|
79
|
+
'main.js',
|
|
80
|
+
'main.jsx',
|
|
81
|
+
'index.ts',
|
|
82
|
+
'index.tsx',
|
|
83
|
+
'index.js',
|
|
84
|
+
'index.jsx',
|
|
85
|
+
];
|
|
86
|
+
const mainEntry = mainFiles.find((file) => tree.exists((0, devkit_1.joinPathFragments)(projectRoot, file)));
|
|
87
|
+
return mainEntry ? (0, devkit_1.joinPathFragments)(projectRoot, mainEntry) : undefined;
|
|
88
|
+
}
|
|
@@ -65,7 +65,6 @@ async function setupSsrGenerator(tree, options) {
|
|
|
65
65
|
compiler: 'babel',
|
|
66
66
|
externalDependencies: 'all',
|
|
67
67
|
outputHashing: 'none',
|
|
68
|
-
isolatedConfig: true,
|
|
69
68
|
webpackConfig: (0, devkit_1.joinPathFragments)(projectRoot, 'webpack.config.js'),
|
|
70
69
|
},
|
|
71
70
|
configurations: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ModuleFederationConfig } from '@nx/webpack/src/utils/module-federation';
|
|
2
|
-
import type {
|
|
2
|
+
import type { AsyncNxComposableWebpackPlugin } from '@nx/webpack';
|
|
3
3
|
/**
|
|
4
4
|
* @param {ModuleFederationConfig} options
|
|
5
|
-
* @return {Promise<
|
|
5
|
+
* @return {Promise<AsyncNxComposableWebpackPlugin>}
|
|
6
6
|
*/
|
|
7
|
-
export declare function withModuleFederation(options: ModuleFederationConfig): Promise<
|
|
7
|
+
export declare function withModuleFederation(options: ModuleFederationConfig): Promise<AsyncNxComposableWebpackPlugin>;
|
|
@@ -5,7 +5,7 @@ const utils_1 = require("./utils");
|
|
|
5
5
|
const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin");
|
|
6
6
|
/**
|
|
7
7
|
* @param {ModuleFederationConfig} options
|
|
8
|
-
* @return {Promise<
|
|
8
|
+
* @return {Promise<AsyncNxComposableWebpackPlugin>}
|
|
9
9
|
*/
|
|
10
10
|
async function withModuleFederation(options) {
|
|
11
11
|
const { sharedDependencies, sharedLibraries, mappedRemotes } = await (0, utils_1.getModuleFederationConfig)(options);
|
|
@@ -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;
|