@nx/rspack 19.7.1 → 20.0.0-beta.3
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/LICENSE +1 -1
- package/README.md +70 -34
- package/executors.json +2 -2
- package/module-federation.js +0 -1
- package/package.json +14 -9
- package/plugin.js +0 -1
- package/src/executors/dev-server/dev-server.impl.js +39 -38
- package/src/executors/dev-server/lib/get-dev-server-config.js +1 -3
- package/src/executors/dev-server/lib/serve-path.js +0 -1
- package/src/executors/dev-server/schema.json +3 -9
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +109 -98
- package/src/executors/module-federation-dev-server/schema.json +1 -3
- package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js +153 -148
- package/src/executors/module-federation-ssr-dev-server/schema.json +1 -4
- package/src/executors/module-federation-static-server/module-federation-static-server.impl.js +117 -125
- package/src/executors/rspack/rspack.impl.js +60 -67
- package/src/executors/rspack/schema.json +6 -26
- package/src/executors/ssr-dev-server/lib/wait-until-server-is-listening.js +0 -1
- package/src/executors/ssr-dev-server/schema.json +1 -4
- package/src/executors/ssr-dev-server/ssr-dev-server.impl.js +26 -40
- package/src/generators/application/application.js +79 -76
- package/src/generators/application/lib/create-ts-config.js +5 -3
- package/src/generators/application/lib/normalize-options.js +12 -7
- package/src/generators/application/schema.json +1 -0
- package/src/generators/configuration/configuration.js +63 -65
- package/src/generators/configuration/schema.json +2 -1
- package/src/generators/init/init.js +58 -59
- package/src/generators/init/schema.json +2 -1
- package/src/generators/preset/preset.js +26 -29
- package/src/generators/preset/schema.json +1 -0
- package/src/index.js +0 -1
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +3 -7
- package/src/plugins/generate-package-json-plugin.js +1 -3
- package/src/plugins/plugin.js +81 -90
- package/src/utils/config.js +7 -11
- package/src/utils/create-compiler.js +21 -25
- package/src/utils/generator-utils.js +55 -66
- package/src/utils/get-copy-patterns.js +1 -3
- package/src/utils/jest-utils.js +0 -1
- package/src/utils/mode-utils.js +0 -1
- package/src/utils/model.js +0 -1
- package/src/utils/module-federation/build-static.remotes.js +57 -61
- package/src/utils/module-federation/dependencies.js +1 -3
- package/src/utils/module-federation/get-remotes-for-host.js +4 -8
- package/src/utils/module-federation/index.js +0 -1
- package/src/utils/module-federation/models/index.js +0 -1
- package/src/utils/module-federation/package-json.js +0 -1
- package/src/utils/module-federation/parse-static-remotes-config.js +2 -3
- package/src/utils/module-federation/plugins/runtime-library-control.plugin.js +1 -2
- package/src/utils/module-federation/public-api.js +0 -1
- package/src/utils/module-federation/remotes.js +0 -1
- package/src/utils/module-federation/secondary-entry-points.js +4 -5
- package/src/utils/module-federation/share.js +22 -19
- package/src/utils/module-federation/start-remote-proxies.js +0 -1
- package/src/utils/module-federation/start-ssr-remote-proxies.js +0 -1
- package/src/utils/module-federation/typescript.js +6 -6
- package/src/utils/module-federation/with-module-federation/package-json.js +0 -1
- package/src/utils/module-federation/with-module-federation/utils.js +41 -43
- package/src/utils/module-federation/with-module-federation/with-module-federation-ssr.js +48 -35
- package/src/utils/module-federation/with-module-federation/with-module-federation.js +56 -38
- package/src/utils/normalize-assets.js +5 -3
- package/src/utils/read-rspack-options.js +23 -27
- package/src/utils/resolve-user-defined-rspack-config.js +0 -1
- package/src/utils/versions.d.ts +2 -2
- package/src/utils/versions.js +2 -3
- package/src/utils/with-nx.js +30 -13
- package/src/utils/with-react.js +11 -5
- package/src/utils/with-web.js +20 -11
- package/module-federation.js.map +0 -1
- package/plugin.js.map +0 -1
- package/src/executors/dev-server/dev-server.impl.js.map +0 -1
- package/src/executors/dev-server/lib/get-dev-server-config.js.map +0 -1
- package/src/executors/dev-server/lib/serve-path.js.map +0 -1
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js.map +0 -1
- package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js.map +0 -1
- package/src/executors/module-federation-static-server/module-federation-static-server.impl.js.map +0 -1
- package/src/executors/rspack/rspack.impl.js.map +0 -1
- package/src/executors/ssr-dev-server/lib/wait-until-server-is-listening.js.map +0 -1
- package/src/executors/ssr-dev-server/ssr-dev-server.impl.js.map +0 -1
- package/src/generators/application/application.js.map +0 -1
- package/src/generators/application/lib/create-ts-config.js.map +0 -1
- package/src/generators/application/lib/normalize-options.js.map +0 -1
- package/src/generators/configuration/configuration.js.map +0 -1
- package/src/generators/init/init.js.map +0 -1
- package/src/generators/preset/preset.js.map +0 -1
- package/src/index.js.map +0 -1
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js.map +0 -1
- package/src/plugins/generate-package-json-plugin.js.map +0 -1
- package/src/plugins/plugin.js.map +0 -1
- package/src/utils/config.js.map +0 -1
- package/src/utils/create-compiler.js.map +0 -1
- package/src/utils/generator-utils.js.map +0 -1
- package/src/utils/get-copy-patterns.js.map +0 -1
- package/src/utils/jest-utils.js.map +0 -1
- package/src/utils/mode-utils.js.map +0 -1
- package/src/utils/model.js.map +0 -1
- package/src/utils/module-federation/build-static.remotes.js.map +0 -1
- package/src/utils/module-federation/dependencies.js.map +0 -1
- package/src/utils/module-federation/get-remotes-for-host.js.map +0 -1
- package/src/utils/module-federation/index.js.map +0 -1
- package/src/utils/module-federation/models/index.js.map +0 -1
- package/src/utils/module-federation/package-json.js.map +0 -1
- package/src/utils/module-federation/parse-static-remotes-config.js.map +0 -1
- package/src/utils/module-federation/plugins/runtime-library-control.plugin.js.map +0 -1
- package/src/utils/module-federation/public-api.js.map +0 -1
- package/src/utils/module-federation/remotes.js.map +0 -1
- package/src/utils/module-federation/secondary-entry-points.js.map +0 -1
- package/src/utils/module-federation/share.js.map +0 -1
- package/src/utils/module-federation/start-remote-proxies.js.map +0 -1
- package/src/utils/module-federation/start-ssr-remote-proxies.js.map +0 -1
- package/src/utils/module-federation/typescript.js.map +0 -1
- package/src/utils/module-federation/with-module-federation/package-json.js.map +0 -1
- package/src/utils/module-federation/with-module-federation/utils.js.map +0 -1
- package/src/utils/module-federation/with-module-federation/with-module-federation-ssr.js.map +0 -1
- package/src/utils/module-federation/with-module-federation/with-module-federation.js.map +0 -1
- package/src/utils/normalize-assets.js.map +0 -1
- package/src/utils/read-rspack-options.js.map +0 -1
- package/src/utils/resolve-user-defined-rspack-config.js.map +0 -1
- package/src/utils/versions.js.map +0 -1
- package/src/utils/with-nx.js.map +0 -1
- package/src/utils/with-react.js.map +0 -1
- package/src/utils/with-web.js.map +0 -1
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,3 +1,72 @@
|
|
|
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>
|
|
7
|
+
|
|
8
|
+
<div style="text-align: center;">
|
|
9
|
+
|
|
10
|
+
[](https://circleci.com/gh/nrwl/nx)
|
|
11
|
+
[]()
|
|
12
|
+
[](https://www.npmjs.com/@nx/workspace)
|
|
13
|
+
[]()
|
|
14
|
+
[](http://commitizen.github.io/cz-cli/)
|
|
15
|
+
[](https://gitter.im/nrwl-nx/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
|
16
|
+
[](https://go.nx.dev/community)
|
|
17
|
+
|
|
18
|
+
</div>
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
<hr>
|
|
22
|
+
|
|
23
|
+
# Nx: Smart Monorepos · Fast CI
|
|
24
|
+
|
|
25
|
+
Nx is a build system, optimized for monorepos, with plugins for popular frameworks and tools and advanced CI capabilities including caching and distribution.
|
|
26
|
+
|
|
27
|
+
This package is a [Rspack plugin for Nx](https://nx.dev/nx-api/rspack).
|
|
28
|
+
|
|
29
|
+
## Getting Started
|
|
30
|
+
|
|
31
|
+
### Creating an Nx Workspace
|
|
32
|
+
|
|
33
|
+
**Using `npx`**
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npx create-nx-workspace
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
**Using `npm init`**
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npm init nx-workspace
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
**Using `yarn create`**
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
yarn create nx-workspace
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Adding Nx to an Existing Repository
|
|
52
|
+
|
|
53
|
+
Run:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
npx nx@latest init
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Documentation & Resources
|
|
60
|
+
|
|
61
|
+
- [Nx.Dev: Documentation, Guides, Tutorials](https://nx.dev)
|
|
62
|
+
- [Intro to Nx](https://nx.dev/getting-started/intro)
|
|
63
|
+
- [Official Nx YouTube Channel](https://www.youtube.com/@NxDevtools)
|
|
64
|
+
- [Blog Posts About Nx](https://nx.dev/blog)
|
|
65
|
+
|
|
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"
|
|
67
|
+
width="100%" alt="Nx - Smart Monorepos · Fast CI"></a></p>
|
|
68
|
+
|
|
69
|
+
|
|
1
70
|
<p style="text-align: center;"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx.png" width="600" alt="Nx - Smart, Fast and Extensible Build System"></p>
|
|
2
71
|
|
|
3
72
|
<hr>
|
|
@@ -43,39 +112,6 @@ First, install the plugin:
|
|
|
43
112
|
npm install --save-dev @nx/rspack
|
|
44
113
|
```
|
|
45
114
|
|
|
46
|
-
Then,
|
|
47
|
-
|
|
48
|
-
```bash
|
|
49
|
-
npx nx g @nx/rspack:rspack-project --skipValidation
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
**Note:** The `--skipValidation` option allows you to overwrite existing build targets.
|
|
53
|
-
|
|
54
|
-
## Workspace libraries
|
|
55
|
-
|
|
56
|
-
The `@nx/rspack` executor support importing workspace libs into the app.
|
|
57
|
-
|
|
58
|
-
```bash
|
|
59
|
-
npx nx g @nx/react:lib mylib
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
Import the new library in your app.
|
|
63
|
-
|
|
64
|
-
```typescript jsx
|
|
65
|
-
// src/app/app.tsx
|
|
66
|
-
import { Mylib } from '@rspack-demo/mylib';
|
|
67
|
-
|
|
68
|
-
// ...
|
|
69
|
-
|
|
70
|
-
export default function App() {
|
|
71
|
-
return <MyLib />;
|
|
72
|
-
}
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
Now, run the dev server again to see the new library in action.
|
|
76
|
-
|
|
77
|
-
```bash
|
|
78
|
-
npm start
|
|
79
|
-
```
|
|
115
|
+
Then, r
|
|
80
116
|
|
|
81
117
|
**Note:** You must restart the server if you make any changes to your library.
|
package/executors.json
CHANGED
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
"rspack": {
|
|
5
5
|
"implementation": "./src/executors/rspack/rspack.impl",
|
|
6
6
|
"schema": "./src/executors/rspack/schema.json",
|
|
7
|
-
"description": "
|
|
7
|
+
"description": "Run Rspack via an executor for a project."
|
|
8
8
|
},
|
|
9
9
|
"dev-server": {
|
|
10
10
|
"implementation": "./src/executors/dev-server/dev-server.impl",
|
|
11
11
|
"schema": "./src/executors/dev-server/schema.json",
|
|
12
|
-
"description": "dev-server
|
|
12
|
+
"description": "Run @rspack/dev-server to serve a project."
|
|
13
13
|
},
|
|
14
14
|
"ssr-dev-server": {
|
|
15
15
|
"implementation": "./src/executors/ssr-dev-server/ssr-dev-server.impl",
|
package/module-federation.js
CHANGED
package/package.json
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/rspack",
|
|
3
|
-
"
|
|
3
|
+
"description": "The Nx Plugin for Rspack contains executors and generators that support building applications using Rspack.",
|
|
4
|
+
"version": "20.0.0-beta.3",
|
|
4
5
|
"type": "commonjs",
|
|
5
6
|
"repository": {
|
|
6
7
|
"type": "git",
|
|
7
|
-
"url": "https://github.com/nrwl/nx
|
|
8
|
+
"url": "https://github.com/nrwl/nx.git",
|
|
8
9
|
"directory": "packages/rspack"
|
|
9
10
|
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/nrwl/nx/issues"
|
|
13
|
+
},
|
|
10
14
|
"keywords": [
|
|
11
15
|
"Monorepo",
|
|
12
|
-
"
|
|
13
|
-
"
|
|
16
|
+
"Rspack",
|
|
17
|
+
"Bundling",
|
|
18
|
+
"Module Federation"
|
|
14
19
|
],
|
|
15
20
|
"author": "Jack Hsu",
|
|
16
21
|
"license": "MIT",
|
|
@@ -19,20 +24,20 @@
|
|
|
19
24
|
"generators": "./generators.json",
|
|
20
25
|
"executors": "./executors.json",
|
|
21
26
|
"dependencies": {
|
|
22
|
-
"@nx/js": "
|
|
23
|
-
"@nx/devkit": "
|
|
27
|
+
"@nx/js": "20.0.0-beta.3",
|
|
28
|
+
"@nx/devkit": "20.0.0-beta.3",
|
|
29
|
+
"@nx/eslint": "20.0.0-beta.3",
|
|
24
30
|
"@phenomnomnominal/tsquery": "~5.0.1",
|
|
25
31
|
"less-loader": "11.1.0",
|
|
26
32
|
"license-webpack-plugin": "^4.0.2",
|
|
27
33
|
"sass-loader": "^12.2.0",
|
|
28
34
|
"stylus-loader": "^7.1.0",
|
|
29
35
|
"postcss-loader": "^8.1.1",
|
|
30
|
-
"@
|
|
31
|
-
"@rspack/core": "^1.0.2",
|
|
36
|
+
"@rspack/core": "^1.0.4",
|
|
32
37
|
"@rspack/plugin-react-refresh": "^1.0.0",
|
|
33
38
|
"@rspack/plugin-minify": "^0.7.5",
|
|
34
39
|
"chalk": "~4.1.0",
|
|
35
|
-
"@nrwl/rspack": "
|
|
40
|
+
"@nrwl/rspack": "20.0.0-beta.3"
|
|
36
41
|
},
|
|
37
42
|
"peerDependencies": {
|
|
38
43
|
"@module-federation/enhanced": "~0.6.0",
|
package/plugin.js
CHANGED
|
@@ -4,4 +4,3 @@ exports.createNodesV2 = exports.createDependencies = void 0;
|
|
|
4
4
|
var plugin_1 = require("./src/plugins/plugin");
|
|
5
5
|
Object.defineProperty(exports, "createDependencies", { enumerable: true, get: function () { return plugin_1.createDependencies; } });
|
|
6
6
|
Object.defineProperty(exports, "createNodesV2", { enumerable: true, get: function () { return plugin_1.createNodesV2; } });
|
|
7
|
-
//# sourceMappingURL=plugin.js.map
|
|
@@ -1,49 +1,50 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = runExecutor;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const devkit_1 = require("@nx/devkit");
|
|
6
5
|
const async_iterable_1 = require("@nx/devkit/src/utils/async-iterable");
|
|
7
6
|
const dev_server_1 = require("@rspack/dev-server");
|
|
8
7
|
const create_compiler_1 = require("../../utils/create-compiler");
|
|
9
8
|
const mode_utils_1 = require("../../utils/mode-utils");
|
|
10
9
|
const get_dev_server_config_1 = require("./lib/get-dev-server-config");
|
|
11
|
-
function runExecutor(options, context) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
10
|
+
async function* runExecutor(options, context) {
|
|
11
|
+
process.env.NODE_ENV ??= options.mode ?? 'development';
|
|
12
|
+
if ((0, mode_utils_1.isMode)(process.env.NODE_ENV)) {
|
|
13
|
+
options.mode = process.env.NODE_ENV;
|
|
14
|
+
}
|
|
15
|
+
const buildTarget = (0, devkit_1.parseTargetString)(options.buildTarget, context.projectGraph);
|
|
16
|
+
const buildOptions = (0, devkit_1.readTargetOptions)(buildTarget, context);
|
|
17
|
+
let devServerConfig = (0, get_dev_server_config_1.getDevServerOptions)(context.root, options, buildOptions);
|
|
18
|
+
const compiler = await (0, create_compiler_1.createCompiler)({ ...buildOptions, devServer: devServerConfig, mode: options.mode }, context);
|
|
19
|
+
// Use the first one if it's MultiCompiler
|
|
20
|
+
// https://webpack.js.org/configuration/dev-server/#root:~:text=Be%20aware%20that%20when%20exporting%20multiple%20configurations%20only%20the%20devServer%20options%20for%20the%20first%20configuration%20will%20be%20taken%20into%20account%20and%20used%20for%20all%20the%20configurations%20in%20the%20array.
|
|
21
|
+
const firstCompiler = (0, create_compiler_1.isMultiCompiler)(compiler)
|
|
22
|
+
? compiler.compilers[0]
|
|
23
|
+
: compiler;
|
|
24
|
+
devServerConfig = {
|
|
25
|
+
...devServerConfig,
|
|
26
|
+
...firstCompiler.options.devServer,
|
|
27
|
+
port: devServerConfig.port,
|
|
28
|
+
};
|
|
29
|
+
const baseUrl = `http://localhost:${options.port ?? 4200}`;
|
|
30
|
+
return yield* (0, async_iterable_1.createAsyncIterable)(({ next }) => {
|
|
31
|
+
const server = new dev_server_1.RspackDevServer({
|
|
32
|
+
...devServerConfig,
|
|
33
|
+
onListening: () => {
|
|
34
|
+
next({
|
|
35
|
+
success: true,
|
|
36
|
+
baseUrl,
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
}, compiler);
|
|
40
|
+
server.compiler.hooks.done.tap('NX Rspack Dev Server', (stats) => {
|
|
41
|
+
if (stats.hasErrors()) {
|
|
42
|
+
devkit_1.logger.error(`NX Compilation failed. See above for more details.`);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
devkit_1.logger.info(`NX Server ready at ${baseUrl}`);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
server.start();
|
|
47
49
|
});
|
|
48
50
|
}
|
|
49
|
-
//# sourceMappingURL=dev-server.impl.js.map
|
|
@@ -31,9 +31,8 @@ function getDevServerOptions(root, serveOptions, buildOptions) {
|
|
|
31
31
|
htmlAcceptHeaders: ['text/html', 'application/xhtml+xml'],
|
|
32
32
|
},
|
|
33
33
|
onListening(server) {
|
|
34
|
-
var _a;
|
|
35
34
|
const isHttps = server.options.https ||
|
|
36
|
-
|
|
35
|
+
server.options.server?.type === 'https';
|
|
37
36
|
devkit_1.logger.info(`NX Web Development Server is listening at ${isHttps ? 'https' : 'http'}://${server.options.host}:${server.options.port}${(0, serve_path_1.buildServePath)(buildOptions)}`);
|
|
38
37
|
},
|
|
39
38
|
open: false,
|
|
@@ -68,4 +67,3 @@ function getSslConfig(root, options) {
|
|
|
68
67
|
cert: (0, fs_1.readFileSync)(path.resolve(root, options.sslCert), 'utf-8'),
|
|
69
68
|
};
|
|
70
69
|
}
|
|
71
|
-
//# sourceMappingURL=get-dev-server-config.js.map
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"$schema": "http://json-schema.org/schema",
|
|
3
3
|
"version": 2,
|
|
4
4
|
"title": "Rspack dev-server executor",
|
|
5
|
-
"description": "",
|
|
5
|
+
"description": "Run @rspack/dev-server to serve a project.",
|
|
6
6
|
"type": "object",
|
|
7
7
|
"properties": {
|
|
8
8
|
"buildTarget": {
|
|
@@ -16,11 +16,7 @@
|
|
|
16
16
|
"mode": {
|
|
17
17
|
"type": "string",
|
|
18
18
|
"description": "Mode to run the server in.",
|
|
19
|
-
"enum": [
|
|
20
|
-
"development",
|
|
21
|
-
"production",
|
|
22
|
-
"none"
|
|
23
|
-
]
|
|
19
|
+
"enum": ["development", "production", "none"]
|
|
24
20
|
},
|
|
25
21
|
"host": {
|
|
26
22
|
"type": "string",
|
|
@@ -45,7 +41,5 @@
|
|
|
45
41
|
"description": "Public URL where the application will be served."
|
|
46
42
|
}
|
|
47
43
|
},
|
|
48
|
-
"required": [
|
|
49
|
-
"buildTarget"
|
|
50
|
-
]
|
|
44
|
+
"required": ["buildTarget"]
|
|
51
45
|
}
|
|
@@ -16,7 +16,9 @@ const dev_server_impl_1 = tslib_1.__importDefault(require("../dev-server/dev-ser
|
|
|
16
16
|
function getBuildOptions(buildTarget, context) {
|
|
17
17
|
const target = (0, devkit_1.parseTargetString)(buildTarget, context);
|
|
18
18
|
const buildOptions = (0, devkit_1.readTargetOptions)(target, context);
|
|
19
|
-
return
|
|
19
|
+
return {
|
|
20
|
+
...buildOptions,
|
|
21
|
+
};
|
|
20
22
|
}
|
|
21
23
|
function startStaticRemotesFileServer(staticRemotesConfig, context, options) {
|
|
22
24
|
if (!staticRemotesConfig.remotes ||
|
|
@@ -61,106 +63,115 @@ function startStaticRemotesFileServer(staticRemotesConfig, context, options) {
|
|
|
61
63
|
}, context);
|
|
62
64
|
return staticRemotesIter;
|
|
63
65
|
}
|
|
64
|
-
function startRemotes(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
66
|
+
async function startRemotes(remotes, context, options, target = 'serve') {
|
|
67
|
+
const remoteIters = [];
|
|
68
|
+
for (const app of remotes) {
|
|
69
|
+
const remoteProjectServeTarget = context.projectGraph.nodes[app].data.targets[target];
|
|
70
|
+
const isUsingModuleFederationDevServerExecutor = remoteProjectServeTarget.executor.includes('module-federation-dev-server');
|
|
71
|
+
const configurationOverride = options.devRemotes?.find((r) => typeof r !== 'string' && r.remoteName === app)?.configuration;
|
|
72
|
+
const defaultOverrides = {
|
|
73
|
+
...(options.host ? { host: options.host } : {}),
|
|
74
|
+
...(options.ssl ? { ssl: options.ssl } : {}),
|
|
75
|
+
...(options.sslCert ? { sslCert: options.sslCert } : {}),
|
|
76
|
+
...(options.sslKey ? { sslKey: options.sslKey } : {}),
|
|
77
|
+
};
|
|
78
|
+
const overrides = target === 'serve'
|
|
79
|
+
? {
|
|
80
|
+
watch: true,
|
|
81
|
+
...(isUsingModuleFederationDevServerExecutor
|
|
75
82
|
? { isInitialHost: false }
|
|
76
|
-
: {})
|
|
77
|
-
|
|
78
|
-
project: app,
|
|
79
|
-
target,
|
|
80
|
-
configuration: configurationOverride !== null && configurationOverride !== void 0 ? configurationOverride : context.configurationName,
|
|
81
|
-
}, overrides, context));
|
|
82
|
-
}
|
|
83
|
-
return remoteIters;
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
function moduleFederationDevServer(options, context) {
|
|
87
|
-
return tslib_1.__asyncGenerator(this, arguments, function* moduleFederationDevServer_1() {
|
|
88
|
-
var _a, _b, _c;
|
|
89
|
-
// Force Node to resolve to look for the nx binary that is inside node_modules
|
|
90
|
-
const nxBin = require.resolve('nx/bin/nx');
|
|
91
|
-
const currIter = options.static
|
|
92
|
-
? (0, file_server_impl_1.default)(Object.assign(Object.assign({}, options), { parallel: false, withDeps: false, spa: false, cors: true, cacheSeconds: -1 }), context)
|
|
93
|
-
: (0, dev_server_impl_1.default)(options, context);
|
|
94
|
-
const p = context.projectsConfigurations.projects[context.projectName];
|
|
95
|
-
const buildOptions = getBuildOptions(options.buildTarget, context);
|
|
96
|
-
let pathToManifestFile = (0, path_1.join)(context.root, p.sourceRoot, 'assets/module-federation.manifest.json');
|
|
97
|
-
if (options.pathToManifestFile) {
|
|
98
|
-
const userPathToManifestFile = (0, path_1.join)(context.root, options.pathToManifestFile);
|
|
99
|
-
if (!(0, fs_1.existsSync)(userPathToManifestFile)) {
|
|
100
|
-
throw new Error(`The provided Module Federation manifest file path does not exist. Please check the file exists at "${userPathToManifestFile}".`);
|
|
83
|
+
: {}),
|
|
84
|
+
...defaultOverrides,
|
|
101
85
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
86
|
+
: { ...defaultOverrides };
|
|
87
|
+
remoteIters.push(await (0, devkit_1.runExecutor)({
|
|
88
|
+
project: app,
|
|
89
|
+
target,
|
|
90
|
+
configuration: configurationOverride ?? context.configurationName,
|
|
91
|
+
}, overrides, context));
|
|
92
|
+
}
|
|
93
|
+
return remoteIters;
|
|
94
|
+
}
|
|
95
|
+
async function* moduleFederationDevServer(options, context) {
|
|
96
|
+
// Force Node to resolve to look for the nx binary that is inside node_modules
|
|
97
|
+
const nxBin = require.resolve('nx/bin/nx');
|
|
98
|
+
const currIter = options.static
|
|
99
|
+
? (0, file_server_impl_1.default)({
|
|
100
|
+
...options,
|
|
101
|
+
parallel: false,
|
|
102
|
+
withDeps: false,
|
|
103
|
+
spa: false,
|
|
104
|
+
cors: true,
|
|
105
|
+
cacheSeconds: -1,
|
|
106
|
+
}, context)
|
|
107
|
+
: (0, dev_server_impl_1.default)(options, context);
|
|
108
|
+
const p = context.projectsConfigurations.projects[context.projectName];
|
|
109
|
+
const buildOptions = getBuildOptions(options.buildTarget, context);
|
|
110
|
+
let pathToManifestFile = (0, path_1.join)(context.root, p.sourceRoot, 'assets/module-federation.manifest.json');
|
|
111
|
+
if (options.pathToManifestFile) {
|
|
112
|
+
const userPathToManifestFile = (0, path_1.join)(context.root, options.pathToManifestFile);
|
|
113
|
+
if (!(0, fs_1.existsSync)(userPathToManifestFile)) {
|
|
114
|
+
throw new Error(`The provided Module Federation manifest file path does not exist. Please check the file exists at "${userPathToManifestFile}".`);
|
|
106
115
|
}
|
|
116
|
+
else if ((0, path_1.extname)(options.pathToManifestFile) !== '.json') {
|
|
117
|
+
throw new Error(`The Module Federation manifest file must be a JSON. Please ensure the file at ${userPathToManifestFile} is a JSON.`);
|
|
118
|
+
}
|
|
119
|
+
pathToManifestFile = userPathToManifestFile;
|
|
120
|
+
}
|
|
121
|
+
if (!options.isInitialHost) {
|
|
122
|
+
return yield* currIter;
|
|
123
|
+
}
|
|
124
|
+
const moduleFederationConfig = (0, module_federation_1.getModuleFederationConfig)(buildOptions.tsConfig, context.root, p.root, 'react');
|
|
125
|
+
const remoteNames = options.devRemotes?.map((r) => typeof r === 'string' ? r : r.remoteName);
|
|
126
|
+
const remotes = (0, module_federation_1.getRemotes)(remoteNames, options.skipRemotes, moduleFederationConfig, {
|
|
127
|
+
projectName: context.projectName,
|
|
128
|
+
projectGraph: context.projectGraph,
|
|
129
|
+
root: context.root,
|
|
130
|
+
}, pathToManifestFile);
|
|
131
|
+
options.staticRemotesPort ??= remotes.staticRemotePort;
|
|
132
|
+
// Set NX_MF_DEV_REMOTES for the Nx Runtime Library Control Plugin
|
|
133
|
+
process.env.NX_MF_DEV_REMOTES = JSON.stringify([
|
|
134
|
+
...(remotes.devRemotes.map((r) => typeof r === 'string' ? r : r.remoteName) ?? []),
|
|
135
|
+
p.name,
|
|
136
|
+
]);
|
|
137
|
+
const staticRemotesConfig = (0, parse_static_remotes_config_1.parseStaticRemotesConfig)([...remotes.staticRemotes, ...remotes.dynamicRemotes], context);
|
|
138
|
+
const mappedLocationsOfStaticRemotes = await (0, build_static_remotes_1.buildStaticRemotes)(staticRemotesConfig, nxBin, context, options);
|
|
139
|
+
const devRemoteIters = await startRemotes(remotes.devRemotes, context, options, 'serve');
|
|
140
|
+
const staticRemotesIter = startStaticRemotesFileServer(staticRemotesConfig, context, options);
|
|
141
|
+
(0, start_remote_proxies_1.startRemoteProxies)(staticRemotesConfig, mappedLocationsOfStaticRemotes, options.ssl
|
|
142
|
+
? {
|
|
143
|
+
pathToCert: (0, path_1.join)(devkit_1.workspaceRoot, options.sslCert),
|
|
144
|
+
pathToKey: (0, path_1.join)(devkit_1.workspaceRoot, options.sslKey),
|
|
145
|
+
}
|
|
146
|
+
: undefined);
|
|
147
|
+
return yield* (0, async_iterable_1.combineAsyncIterables)(currIter, ...devRemoteIters, ...(staticRemotesIter ? [staticRemotesIter] : []), (0, async_iterable_1.createAsyncIterable)(async ({ next, done }) => {
|
|
107
148
|
if (!options.isInitialHost) {
|
|
108
|
-
|
|
149
|
+
done();
|
|
150
|
+
return;
|
|
109
151
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if (!options.isInitialHost) {
|
|
136
|
-
done();
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
if (remotes.remotePorts.length === 0) {
|
|
140
|
-
done();
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
try {
|
|
144
|
-
const host = (_b = options.host) !== null && _b !== void 0 ? _b : 'localhost';
|
|
145
|
-
const baseUrl = `http${options.ssl ? 's' : ''}://${host}:${options.port}`;
|
|
146
|
-
const portsToWaitFor = staticRemotesIter
|
|
147
|
-
? [options.staticRemotesPort, ...remotes.remotePorts]
|
|
148
|
-
: [...remotes.remotePorts];
|
|
149
|
-
yield Promise.all(portsToWaitFor.map((port) => (0, wait_for_port_open_1.waitForPortOpen)(port, {
|
|
150
|
-
retries: 480,
|
|
151
|
-
retryDelay: 2500,
|
|
152
|
-
host: host,
|
|
153
|
-
})));
|
|
154
|
-
devkit_1.logger.info(`NX All remotes started, server ready at ${baseUrl}`);
|
|
155
|
-
next({ success: true, baseUrl: baseUrl });
|
|
156
|
-
}
|
|
157
|
-
catch (err) {
|
|
158
|
-
throw new Error(`Failed to start remotes. Check above for any errors.`);
|
|
159
|
-
}
|
|
160
|
-
finally {
|
|
161
|
-
done();
|
|
162
|
-
}
|
|
163
|
-
})))))));
|
|
164
|
-
});
|
|
152
|
+
if (remotes.remotePorts.length === 0) {
|
|
153
|
+
done();
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
try {
|
|
157
|
+
const host = options.host ?? 'localhost';
|
|
158
|
+
const baseUrl = `http${options.ssl ? 's' : ''}://${host}:${options.port}`;
|
|
159
|
+
const portsToWaitFor = staticRemotesIter
|
|
160
|
+
? [options.staticRemotesPort, ...remotes.remotePorts]
|
|
161
|
+
: [...remotes.remotePorts];
|
|
162
|
+
await Promise.all(portsToWaitFor.map((port) => (0, wait_for_port_open_1.waitForPortOpen)(port, {
|
|
163
|
+
retries: 480,
|
|
164
|
+
retryDelay: 2500,
|
|
165
|
+
host: host,
|
|
166
|
+
})));
|
|
167
|
+
devkit_1.logger.info(`NX All remotes started, server ready at ${baseUrl}`);
|
|
168
|
+
next({ success: true, baseUrl: baseUrl });
|
|
169
|
+
}
|
|
170
|
+
catch (err) {
|
|
171
|
+
throw new Error(`Failed to start remotes. Check above for any errors.`);
|
|
172
|
+
}
|
|
173
|
+
finally {
|
|
174
|
+
done();
|
|
175
|
+
}
|
|
176
|
+
}));
|
|
165
177
|
}
|
|
166
|
-
//# sourceMappingURL=module-federation-dev-server.impl.js.map
|