@nx/react 17.2.3 → 17.2.5
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/README.md +9 -4
- package/package.json +6 -6
- package/plugins/component-testing/index.js +16 -7
- package/src/generators/application/files/base-webpack/src/index.html +0 -2
- package/src/generators/component/files/__fileName__.tsx__tmpl__ +40 -23
- package/src/generators/component/lib/normalize-options.js +2 -0
- package/src/generators/component/schema.d.ts +2 -0
- package/src/module-federation/with-module-federation.js +5 -3
package/README.md
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
<p style="text-align: center;"
|
|
1
|
+
<p style="text-align: center;">
|
|
2
|
+
<picture>
|
|
3
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-dark.svg">
|
|
4
|
+
<img alt="Nx - Smart Monorepos · Fast CI" src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-light.svg" width="100%">
|
|
5
|
+
</picture>
|
|
6
|
+
</p>
|
|
2
7
|
|
|
3
8
|
<div style="text-align: center;">
|
|
4
9
|
|
|
@@ -15,9 +20,9 @@
|
|
|
15
20
|
|
|
16
21
|
<hr>
|
|
17
22
|
|
|
18
|
-
# Nx: Smart
|
|
23
|
+
# Nx: Smart Monorepos · Fast CI
|
|
19
24
|
|
|
20
|
-
Nx is a
|
|
25
|
+
Nx is a build system with built-in tooling and advanced CI capabilities. It helps you maintain and scale monorepos, both locally and on CI.
|
|
21
26
|
|
|
22
27
|
This package is a [React plugin for Nx](https://nx.dev/packages/react).
|
|
23
28
|
|
|
@@ -59,5 +64,5 @@ npx nx@latest init
|
|
|
59
64
|
- [Blog Posts About Nx](https://blog.nrwl.io/nx/home)
|
|
60
65
|
|
|
61
66
|
<p style="text-align: center;"><a href="https://nx.dev/#learning-materials" target="_blank" rel="noreferrer"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-courses-and-videos.svg"
|
|
62
|
-
width="100%" alt="Nx - Smart
|
|
67
|
+
width="100%" alt="Nx - Smart Monorepos · Fast CI"></a></p>
|
|
63
68
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "v17.2.5",
|
|
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": "
|
|
41
|
-
"@nx/js": "
|
|
42
|
-
"@nx/eslint": "
|
|
43
|
-
"@nx/web": "
|
|
44
|
-
"@nrwl/react": "
|
|
40
|
+
"@nx/devkit": "v17.2.5",
|
|
41
|
+
"@nx/js": "v17.2.5",
|
|
42
|
+
"@nx/eslint": "v17.2.5",
|
|
43
|
+
"@nx/web": "v17.2.5",
|
|
44
|
+
"@nrwl/react": "v17.2.5"
|
|
45
45
|
},
|
|
46
46
|
"publishConfig": {
|
|
47
47
|
"access": "public"
|
|
@@ -123,7 +123,6 @@ function withSchemaDefaults(target, context) {
|
|
|
123
123
|
options.maxWorkers ??= 2;
|
|
124
124
|
options.fileReplacements ??= [];
|
|
125
125
|
options.buildLibsFromSource ??= true;
|
|
126
|
-
options.generateIndexHtml ??= true;
|
|
127
126
|
return options;
|
|
128
127
|
}
|
|
129
128
|
function buildTargetWebpack(ctx, buildTarget, componentTestingProjectName) {
|
|
@@ -141,7 +140,9 @@ function buildTargetWebpack(ctx, buildTarget, componentTestingProjectName) {
|
|
|
141
140
|
const context = (0, ct_helpers_1.createExecutorContext)(graph, buildableProjectConfig.targets, parsed.project, parsed.target, parsed.target);
|
|
142
141
|
const { normalizeOptions, } = require('@nx/webpack/src/executors/webpack/lib/normalize-options');
|
|
143
142
|
const { resolveUserDefinedWebpackConfig, } = require('@nx/webpack/src/utils/webpack/resolve-user-defined-webpack-config');
|
|
143
|
+
const { composePluginsSync } = require('@nx/webpack/src/utils/config');
|
|
144
144
|
const { withNx } = require('@nx/webpack/src/utils/with-nx');
|
|
145
|
+
const { withWeb } = require('@nx/webpack/src/utils/with-web');
|
|
145
146
|
const options = normalizeOptions(withSchemaDefaults(parsed, context), devkit_1.workspaceRoot, buildableProjectConfig.root, buildableProjectConfig.sourceRoot);
|
|
146
147
|
let customWebpack;
|
|
147
148
|
if (options.webpackConfig) {
|
|
@@ -151,12 +152,20 @@ function buildTargetWebpack(ctx, buildTarget, componentTestingProjectName) {
|
|
|
151
152
|
}
|
|
152
153
|
return async () => {
|
|
153
154
|
customWebpack = await customWebpack;
|
|
154
|
-
// TODO(
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
155
|
+
// TODO(v18): Once webpackConfig is always set in @nx/webpack:webpack and isolatedConfig is removed, we no longer need this default.
|
|
156
|
+
const configure = composePluginsSync(withNx(), withWeb());
|
|
157
|
+
const defaultWebpack = configure({}, {
|
|
158
|
+
options: {
|
|
159
|
+
...options,
|
|
160
|
+
// cypress will generate its own index.html from component-index.html
|
|
161
|
+
generateIndexHtml: false,
|
|
162
|
+
// causes issues with buildable libraries with ENOENT: no such file or directory, scandir error
|
|
163
|
+
extractLicenses: false,
|
|
164
|
+
root: devkit_1.workspaceRoot,
|
|
165
|
+
projectRoot: ctProjectConfig.root,
|
|
166
|
+
sourceRoot: ctProjectConfig.sourceRoot,
|
|
167
|
+
},
|
|
168
|
+
context,
|
|
160
169
|
});
|
|
161
170
|
if (customWebpack) {
|
|
162
171
|
return await customWebpack(defaultWebpack, {
|
|
@@ -32,13 +32,30 @@ const Styled<%= className %> = styled.div`
|
|
|
32
32
|
color: pink;
|
|
33
33
|
`;
|
|
34
34
|
<% }%>
|
|
35
|
-
<% if
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
<% if(!isNextPage) { %>
|
|
36
|
+
<% if (classComponent) { %>
|
|
37
|
+
export class <%= className %> extends Component<<%= className %>Props> {
|
|
38
|
+
override render() {
|
|
39
|
+
return (
|
|
40
|
+
<<%= wrapper %><%- extras %>>
|
|
41
|
+
<%= styledModule === 'styled-jsx' ? `<style jsx>{\`div { color: pink; }\`}</style>` : `` %>
|
|
42
|
+
<p>Welcome to <%= className %>!</p>
|
|
43
|
+
<% if (routing) { %>
|
|
44
|
+
<ul>
|
|
45
|
+
<li><Link to="/"><%= name %> root</Link></li>
|
|
46
|
+
</ul>
|
|
47
|
+
<Route path="/" element={<div>This is the <%= name %> root route.</div>} />
|
|
48
|
+
<% } %>
|
|
49
|
+
</<%= wrapper %>>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
<% } else { %>
|
|
54
|
+
export function <%= className %>(props: <%= className %>Props) {
|
|
38
55
|
return (
|
|
39
56
|
<<%= wrapper %><%- extras %>>
|
|
40
|
-
|
|
41
|
-
<
|
|
57
|
+
<% if (styledModule === 'styled-jsx') { %><style jsx>{`div { color: pink; }`}</style><% } %>
|
|
58
|
+
<h1>Welcome to <%= className %>!</h1>
|
|
42
59
|
<% if (routing) { %>
|
|
43
60
|
<ul>
|
|
44
61
|
<li><Link to="/"><%= name %> root</Link></li>
|
|
@@ -47,25 +64,25 @@ export class <%= className %> extends Component<<%= className %>Props> {
|
|
|
47
64
|
<% } %>
|
|
48
65
|
</<%= wrapper %>>
|
|
49
66
|
);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
67
|
+
};
|
|
68
|
+
<% } %>
|
|
69
|
+
|
|
70
|
+
export default <%= className %>;
|
|
52
71
|
<% } else { %>
|
|
53
|
-
export function <%= className %>(props: <%= className %>Props) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
};
|
|
72
|
+
export default function <%= className %>(props: <%= className %>Props) {
|
|
73
|
+
return (
|
|
74
|
+
<<%= wrapper %><%- extras %>>
|
|
75
|
+
<% if (styledModule === 'styled-jsx') { %><style jsx>{`div { color: pink; }`}</style><% } %>
|
|
76
|
+
<h1>Welcome to <%= className %>!</h1>
|
|
77
|
+
<% if (routing) { %>
|
|
78
|
+
<ul>
|
|
79
|
+
<li><Link to="/"><%= name %> root</Link></li>
|
|
80
|
+
</ul>
|
|
81
|
+
<Route path="/" element={<div>This is the <%= name %> root route.</div>} />
|
|
82
|
+
<% } %>
|
|
83
|
+
</<%= wrapper %>>
|
|
84
|
+
);
|
|
85
|
+
};
|
|
67
86
|
<% } %>
|
|
68
87
|
|
|
69
|
-
export default <%= className %>;
|
|
70
|
-
|
|
71
88
|
<% if (inSourceTests === true) { %> <%- inSourceVitestTests %> <% } %>
|
|
@@ -33,6 +33,8 @@ async function normalizeOptions(tree, options) {
|
|
|
33
33
|
options.routing = options.routing ?? false;
|
|
34
34
|
options.globalCss = options.globalCss ?? false;
|
|
35
35
|
options.inSourceTests = options.inSourceTests ?? false;
|
|
36
|
+
//TODO (nicholas): Remove when Next page generator is removed
|
|
37
|
+
options.isNextPage = options.isNextPage ?? false;
|
|
36
38
|
return {
|
|
37
39
|
...options,
|
|
38
40
|
projectName,
|
|
@@ -33,6 +33,8 @@ export interface Schema {
|
|
|
33
33
|
// Used by other wrapping generators to preserve previous behavior
|
|
34
34
|
// e.g. @nx/next:component
|
|
35
35
|
derivedDirectory?: string;
|
|
36
|
+
// Used by Next.js to determine how React should generate the page
|
|
37
|
+
isNextPage?: boolean;
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
export interface NormalizedSchema extends Schema {
|
|
@@ -3,16 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.withModuleFederation = void 0;
|
|
4
4
|
const utils_1 = require("./utils");
|
|
5
5
|
const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin");
|
|
6
|
+
const isVarOrWindow = (libType) => libType === 'var' || libType === 'window';
|
|
6
7
|
/**
|
|
7
8
|
* @param {ModuleFederationConfig} options
|
|
8
9
|
* @return {Promise<AsyncNxComposableWebpackPlugin>}
|
|
9
10
|
*/
|
|
10
11
|
async function withModuleFederation(options) {
|
|
11
12
|
const { sharedDependencies, sharedLibraries, mappedRemotes } = await (0, utils_1.getModuleFederationConfig)(options);
|
|
13
|
+
const isGlobal = isVarOrWindow(options.library?.type);
|
|
12
14
|
return (config, ctx) => {
|
|
13
15
|
config.output.uniqueName = options.name;
|
|
14
16
|
config.output.publicPath = 'auto';
|
|
15
|
-
if (
|
|
17
|
+
if (isGlobal) {
|
|
16
18
|
config.output.scriptType = 'text/javascript';
|
|
17
19
|
}
|
|
18
20
|
config.optimization = {
|
|
@@ -20,7 +22,7 @@ async function withModuleFederation(options) {
|
|
|
20
22
|
};
|
|
21
23
|
config.experiments = {
|
|
22
24
|
...config.experiments,
|
|
23
|
-
outputModule: !
|
|
25
|
+
outputModule: !isGlobal,
|
|
24
26
|
};
|
|
25
27
|
config.plugins.push(new ModuleFederationPlugin({
|
|
26
28
|
name: options.name,
|
|
@@ -37,7 +39,7 @@ async function withModuleFederation(options) {
|
|
|
37
39
|
* { appX: 'appX@http://localhost:3001/remoteEntry.js' }
|
|
38
40
|
* { appY: 'appY@http://localhost:3002/remoteEntry.js' }
|
|
39
41
|
*/
|
|
40
|
-
...(
|
|
42
|
+
...(isGlobal ? { remoteType: 'script' } : {}),
|
|
41
43
|
}), sharedLibraries.getReplacementPlugin());
|
|
42
44
|
return config;
|
|
43
45
|
};
|