@nx/rspack 19.8.0 → 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.js +0 -1
- 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
|
@@ -18,4 +18,3 @@ const with_module_federation_1 = require("./with-module-federation/with-module-f
|
|
|
18
18
|
Object.defineProperty(exports, "withModuleFederation", { enumerable: true, get: function () { return with_module_federation_1.withModuleFederation; } });
|
|
19
19
|
const with_module_federation_ssr_1 = require("./with-module-federation/with-module-federation-ssr");
|
|
20
20
|
Object.defineProperty(exports, "withModuleFederationForSSR", { enumerable: true, get: function () { return with_module_federation_ssr_1.withModuleFederationForSSR; } });
|
|
21
|
-
//# sourceMappingURL=public-api.js.map
|
|
@@ -15,10 +15,10 @@ function collectWorkspaceLibrarySecondaryEntryPoints(library, tsconfigPathAliase
|
|
|
15
15
|
if (needsSecondaryEntryPointsCollected) {
|
|
16
16
|
const tsConfigAliasesForLibWithSecondaryEntryPoints = Object.entries(tsconfigPathAliases).reduce((acc, [tsKey, tsPaths]) => {
|
|
17
17
|
if (!tsKey.startsWith(library.importKey)) {
|
|
18
|
-
return
|
|
18
|
+
return { ...acc };
|
|
19
19
|
}
|
|
20
20
|
if (tsPaths.some((path) => path.startsWith(`${library.root}/`))) {
|
|
21
|
-
acc =
|
|
21
|
+
acc = { ...acc, [tsKey]: tsPaths };
|
|
22
22
|
}
|
|
23
23
|
return acc;
|
|
24
24
|
}, {});
|
|
@@ -58,7 +58,7 @@ function recursivelyCollectSecondaryEntryPointsFromDirectory(pkgName, pkgVersion
|
|
|
58
58
|
collectedPackages.push({ name, version: pkgVersion });
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
-
catch
|
|
61
|
+
catch {
|
|
62
62
|
// do nothing
|
|
63
63
|
}
|
|
64
64
|
}
|
|
@@ -86,7 +86,7 @@ function collectPackageSecondaryEntryPoints(pkgName, pkgVersion, collectedPackag
|
|
|
86
86
|
({ path: packageJsonPath, packageJson } = (0, package_json_1.readModulePackageJson)(pkgName));
|
|
87
87
|
pathToPackage = (0, path_1.dirname)(packageJsonPath);
|
|
88
88
|
}
|
|
89
|
-
catch
|
|
89
|
+
catch {
|
|
90
90
|
// the package.json might not resolve if the package has the "exports"
|
|
91
91
|
// entry and is not exporting the package.json file, fall back to trying
|
|
92
92
|
// to find it from the top-level node_modules
|
|
@@ -102,4 +102,3 @@ function collectPackageSecondaryEntryPoints(pkgName, pkgVersion, collectedPackag
|
|
|
102
102
|
const subDirs = getNonNodeModulesSubDirs(pathToPackage);
|
|
103
103
|
recursivelyCollectSecondaryEntryPointsFromDirectory(pkgName, pkgVersion, pathToPackage, exports, subDirs, collectedPackages);
|
|
104
104
|
}
|
|
105
|
-
//# sourceMappingURL=secondary-entry-points.js.map
|
|
@@ -19,9 +19,7 @@ const typescript_1 = require("./typescript");
|
|
|
19
19
|
* @param workspaceLibs - The Nx Workspace Libraries to share
|
|
20
20
|
* @param tsConfigPath - The path to TS Config File that contains the Path Mappings for the Libraries
|
|
21
21
|
*/
|
|
22
|
-
function shareWorkspaceLibraries(workspaceLibs, tsConfigPath) {
|
|
23
|
-
var _a;
|
|
24
|
-
if (tsConfigPath === void 0) { tsConfigPath = (_a = process.env.NX_TSCONFIG_PATH) !== null && _a !== void 0 ? _a : (0, typescript_1.getRootTsConfigPath)(); }
|
|
22
|
+
function shareWorkspaceLibraries(workspaceLibs, tsConfigPath = process.env.NX_TSCONFIG_PATH ?? (0, typescript_1.getRootTsConfigPath)()) {
|
|
25
23
|
if (!workspaceLibs) {
|
|
26
24
|
return getEmptySharedLibrariesConfig();
|
|
27
25
|
}
|
|
@@ -54,10 +52,12 @@ function shareWorkspaceLibraries(workspaceLibs, tsConfigPath) {
|
|
|
54
52
|
});
|
|
55
53
|
}
|
|
56
54
|
return {
|
|
57
|
-
getAliases: () => pathMappings.reduce((aliases, library) => (
|
|
55
|
+
getAliases: () => pathMappings.reduce((aliases, library) => ({
|
|
56
|
+
...aliases,
|
|
58
57
|
// If the library path ends in a wildcard, remove it as webpack can't handle this in resolve.alias
|
|
59
58
|
// e.g. path/to/my/lib/* -> path/to/my/lib
|
|
60
|
-
[library.name]: library.path.replace(/\/\*$/, '')
|
|
59
|
+
[library.name]: library.path.replace(/\/\*$/, ''),
|
|
60
|
+
}), {}),
|
|
61
61
|
getLibraries: (projectRoot, eager) => {
|
|
62
62
|
let pkgJson = null;
|
|
63
63
|
if (projectRoot &&
|
|
@@ -65,9 +65,8 @@ function shareWorkspaceLibraries(workspaceLibs, tsConfigPath) {
|
|
|
65
65
|
pkgJson = (0, devkit_1.readJsonFile)((0, devkit_1.joinPathFragments)(devkit_1.workspaceRoot, projectRoot, 'package.json'));
|
|
66
66
|
}
|
|
67
67
|
return pathMappings.reduce((libraries, library) => {
|
|
68
|
-
var _a;
|
|
69
68
|
// Check to see if the library version is declared in the app's package.json
|
|
70
|
-
let version =
|
|
69
|
+
let version = pkgJson?.dependencies?.[library.name];
|
|
71
70
|
if (!version && workspaceLibs.length > 0) {
|
|
72
71
|
const workspaceLib = workspaceLibs.find((lib) => lib.importKey === library.name);
|
|
73
72
|
const libPackageJsonPath = workspaceLib
|
|
@@ -80,12 +79,18 @@ function shareWorkspaceLibraries(workspaceLibs, tsConfigPath) {
|
|
|
80
79
|
}
|
|
81
80
|
}
|
|
82
81
|
}
|
|
83
|
-
return
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
82
|
+
return {
|
|
83
|
+
...libraries,
|
|
84
|
+
[library.name]: {
|
|
85
|
+
...(version
|
|
86
|
+
? {
|
|
87
|
+
requiredVersion: version,
|
|
88
|
+
singleton: true,
|
|
89
|
+
}
|
|
90
|
+
: { requiredVersion: false }),
|
|
91
|
+
eager,
|
|
92
|
+
},
|
|
93
|
+
};
|
|
89
94
|
}, {});
|
|
90
95
|
},
|
|
91
96
|
getReplacementPlugin: () => new core_1.NormalModuleReplacementPlugin(/./, (req) => {
|
|
@@ -140,8 +145,7 @@ function sharePackages(packages) {
|
|
|
140
145
|
const pkgJson = (0, package_json_1.readRootPackageJson)();
|
|
141
146
|
const allPackages = [];
|
|
142
147
|
packages.forEach((pkg) => {
|
|
143
|
-
|
|
144
|
-
const pkgVersion = (_b = (_a = pkgJson.dependencies) === null || _a === void 0 ? void 0 : _a[pkg]) !== null && _b !== void 0 ? _b : (_c = pkgJson.devDependencies) === null || _c === void 0 ? void 0 : _c[pkg];
|
|
148
|
+
const pkgVersion = pkgJson.dependencies?.[pkg] ?? pkgJson.devDependencies?.[pkg];
|
|
145
149
|
allPackages.push({ name: pkg, version: pkgVersion });
|
|
146
150
|
(0, secondary_entry_points_1.collectPackageSecondaryEntryPoints)(pkg, pkgVersion, allPackages);
|
|
147
151
|
});
|
|
@@ -205,13 +209,13 @@ function applyAdditionalShared(sharedConfig, additionalShared, projectGraph) {
|
|
|
205
209
|
}
|
|
206
210
|
}
|
|
207
211
|
function addStringDependencyToSharedConfig(sharedConfig, dependency, projectGraph) {
|
|
208
|
-
var _a, _b, _c, _d;
|
|
209
212
|
if (projectGraph.nodes[dependency]) {
|
|
210
213
|
sharedConfig[dependency] = { requiredVersion: false };
|
|
211
214
|
}
|
|
212
|
-
else if (
|
|
215
|
+
else if (projectGraph.externalNodes?.[`npm:${dependency}`]) {
|
|
213
216
|
const pkgJson = (0, package_json_1.readRootPackageJson)();
|
|
214
|
-
const config = getNpmPackageSharedConfig(dependency,
|
|
217
|
+
const config = getNpmPackageSharedConfig(dependency, pkgJson.dependencies?.[dependency] ??
|
|
218
|
+
pkgJson.devDependencies?.[dependency]);
|
|
215
219
|
if (!config) {
|
|
216
220
|
return;
|
|
217
221
|
}
|
|
@@ -229,4 +233,3 @@ function getEmptySharedLibrariesConfig() {
|
|
|
229
233
|
getReplacementPlugin: () => new core_1.NormalModuleReplacementPlugin(/./, () => undefined),
|
|
230
234
|
};
|
|
231
235
|
}
|
|
232
|
-
//# sourceMappingURL=share.js.map
|
|
@@ -8,9 +8,7 @@ const path_1 = require("path");
|
|
|
8
8
|
const devkit_1 = require("@nx/devkit");
|
|
9
9
|
const tsConfig = new Map();
|
|
10
10
|
const tsPathMappings = new Map();
|
|
11
|
-
function readTsPathMappings(tsConfigPath) {
|
|
12
|
-
var _a, _b, _c;
|
|
13
|
-
if (tsConfigPath === void 0) { tsConfigPath = (_a = process.env.NX_TSCONFIG_PATH) !== null && _a !== void 0 ? _a : getRootTsConfigPath(); }
|
|
11
|
+
function readTsPathMappings(tsConfigPath = process.env.NX_TSCONFIG_PATH ?? getRootTsConfigPath()) {
|
|
14
12
|
if (tsPathMappings.has(tsConfigPath)) {
|
|
15
13
|
return tsPathMappings.get(tsConfigPath);
|
|
16
14
|
}
|
|
@@ -18,8 +16,11 @@ function readTsPathMappings(tsConfigPath) {
|
|
|
18
16
|
tsConfig.set(tsConfigPath, readTsConfiguration(tsConfigPath));
|
|
19
17
|
}
|
|
20
18
|
tsPathMappings.set(tsConfigPath, {});
|
|
21
|
-
Object.entries(
|
|
22
|
-
tsPathMappings.set(tsConfigPath,
|
|
19
|
+
Object.entries(tsConfig.get(tsConfigPath).options?.paths ?? {}).forEach(([alias, paths]) => {
|
|
20
|
+
tsPathMappings.set(tsConfigPath, {
|
|
21
|
+
...tsPathMappings.get(tsConfigPath),
|
|
22
|
+
[alias]: paths.map((path) => path.replace(/^\.\//, '')),
|
|
23
|
+
});
|
|
23
24
|
});
|
|
24
25
|
return tsPathMappings.get(tsConfigPath);
|
|
25
26
|
}
|
|
@@ -50,4 +51,3 @@ function getRootTsConfigFileName() {
|
|
|
50
51
|
}
|
|
51
52
|
return null;
|
|
52
53
|
}
|
|
53
|
-
//# sourceMappingURL=typescript.js.map
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getFunctionDeterminateRemoteUrl = getFunctionDeterminateRemoteUrl;
|
|
4
4
|
exports.getModuleFederationConfig = getModuleFederationConfig;
|
|
5
|
-
const tslib_1 = require("tslib");
|
|
6
5
|
const devkit_1 = require("@nx/devkit");
|
|
7
6
|
const project_graph_1 = require("nx/src/project-graph/project-graph");
|
|
8
7
|
const dependencies_1 = require("../dependencies");
|
|
@@ -12,7 +11,6 @@ function getFunctionDeterminateRemoteUrl(isServer = false) {
|
|
|
12
11
|
const target = 'serve';
|
|
13
12
|
const remoteEntry = isServer ? 'server/remoteEntry.js' : 'remoteEntry.js';
|
|
14
13
|
return function (remote) {
|
|
15
|
-
var _a, _b, _c, _d, _e;
|
|
16
14
|
const mappedStaticRemotesFromEnv = process.env
|
|
17
15
|
.NX_MF_DEV_SERVER_STATIC_REMOTES
|
|
18
16
|
? JSON.parse(process.env.NX_MF_DEV_SERVER_STATIC_REMOTES)
|
|
@@ -27,52 +25,52 @@ function getFunctionDeterminateRemoteUrl(isServer = false) {
|
|
|
27
25
|
catch (e) {
|
|
28
26
|
throw new Error(`Cannot find remote: "${remote}". Check that the remote name is correct in your module federation config file.\n`);
|
|
29
27
|
}
|
|
30
|
-
const serveTarget =
|
|
28
|
+
const serveTarget = remoteConfiguration?.targets?.[target];
|
|
31
29
|
if (!serveTarget) {
|
|
32
30
|
throw new Error(`Cannot automatically determine URL of remote (${remote}). Looked for property "host" in the project's "${serveTarget}" target.\n
|
|
33
31
|
You can also use the tuple syntax in your webpack config to configure your remotes. e.g. \`remotes: [['remote1', 'http://localhost:4201']]\``);
|
|
34
32
|
}
|
|
35
|
-
const host =
|
|
36
|
-
|
|
33
|
+
const host = serveTarget.options?.host ??
|
|
34
|
+
`http${serveTarget.options.ssl ? 's' : ''}://localhost`;
|
|
35
|
+
const port = serveTarget.options?.port ?? 4201;
|
|
37
36
|
return `${host.endsWith('/') ? host.slice(0, -1) : host}:${port}/${remoteEntry}`;
|
|
38
37
|
};
|
|
39
38
|
}
|
|
40
|
-
function getModuleFederationConfig(
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
39
|
+
async function getModuleFederationConfig(mfConfig, options = { isServer: false }) {
|
|
40
|
+
let projectGraph;
|
|
41
|
+
try {
|
|
42
|
+
projectGraph = (0, devkit_1.readCachedProjectGraph)();
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
projectGraph = await (0, devkit_1.createProjectGraphAsync)();
|
|
46
|
+
}
|
|
47
|
+
const project = projectGraph.nodes[mfConfig.name]?.data;
|
|
48
|
+
if (!project) {
|
|
49
|
+
throw Error(`Cannot find project "${mfConfig.name}". Check that the name is correct in module-federation.config.js`);
|
|
50
|
+
}
|
|
51
|
+
const dependencies = (0, dependencies_1.getDependentPackagesForProject)(projectGraph, mfConfig.name);
|
|
52
|
+
if (mfConfig.shared) {
|
|
53
|
+
dependencies.workspaceLibraries = dependencies.workspaceLibraries.filter((lib) => mfConfig.shared(lib.importKey, {}) !== false);
|
|
54
|
+
dependencies.npmPackages = dependencies.npmPackages.filter((pkg) => mfConfig.shared(pkg, {}) !== false);
|
|
55
|
+
}
|
|
56
|
+
const sharedLibraries = (0, share_1.shareWorkspaceLibraries)(dependencies.workspaceLibraries);
|
|
57
|
+
const npmPackages = (0, share_1.sharePackages)(dependencies.npmPackages);
|
|
58
|
+
const sharedDependencies = {
|
|
59
|
+
...sharedLibraries.getLibraries(project.root),
|
|
60
|
+
...npmPackages,
|
|
61
|
+
};
|
|
62
|
+
(0, share_1.applySharedFunction)(sharedDependencies, mfConfig.shared);
|
|
63
|
+
(0, share_1.applyAdditionalShared)(sharedDependencies, mfConfig.additionalShared, projectGraph);
|
|
64
|
+
// Choose the correct mapRemotes function based on the server state.
|
|
65
|
+
const mapRemotesFunction = options.isServer ? remotes_1.mapRemotesForSSR : remotes_1.mapRemotes;
|
|
66
|
+
// Determine the URL function, either from provided options or by using a default.
|
|
67
|
+
const determineRemoteUrlFunction = options.determineRemoteUrl
|
|
68
|
+
? options.determineRemoteUrl
|
|
69
|
+
: getFunctionDeterminateRemoteUrl(options.isServer);
|
|
70
|
+
// Map the remotes if they exist, otherwise default to an empty object.
|
|
71
|
+
let mappedRemotes = {};
|
|
72
|
+
if (mfConfig.remotes && mfConfig.remotes.length > 0) {
|
|
73
|
+
mappedRemotes = mapRemotesFunction(mfConfig.remotes, 'js', determineRemoteUrlFunction);
|
|
74
|
+
}
|
|
75
|
+
return { sharedLibraries, sharedDependencies, mappedRemotes };
|
|
77
76
|
}
|
|
78
|
-
//# sourceMappingURL=utils.js.map
|
|
@@ -1,42 +1,55 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.withModuleFederationForSSR = withModuleFederationForSSR;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const core_1 = require("@rspack/core");
|
|
6
5
|
const utils_1 = require("./utils");
|
|
7
|
-
function withModuleFederationForSSR(options, configOverride) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
isServer: true,
|
|
14
|
-
});
|
|
15
|
-
return (config, { context }) => {
|
|
16
|
-
var _a, _b, _c;
|
|
17
|
-
config.target = 'async-node';
|
|
18
|
-
config.output.uniqueName = options.name;
|
|
19
|
-
config.optimization = Object.assign(Object.assign({}, ((_a = config.optimization) !== null && _a !== void 0 ? _a : {})), { runtimeChunk: false });
|
|
20
|
-
config.plugins.push(
|
|
21
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
22
|
-
new (require('@module-federation/enhanced/rspack').ModuleFederationPlugin)(Object.assign(Object.assign({ name: options.name, filename: 'remoteEntry.js', exposes: options.exposes, remotes: mappedRemotes, shared: Object.assign({}, sharedDependencies), isServer: true }, (configOverride ? configOverride : {})), { runtimePlugins: process.env.NX_MF_DEV_REMOTES &&
|
|
23
|
-
!options.disableNxRuntimeLibraryControlPlugin
|
|
24
|
-
? [
|
|
25
|
-
...((_b = configOverride === null || configOverride === void 0 ? void 0 : configOverride.runtimePlugins) !== null && _b !== void 0 ? _b : []),
|
|
26
|
-
require.resolve('@module-federation/node/runtimePlugin'),
|
|
27
|
-
require.resolve('@nx/rspack/src/utils/module-federation/plugins/runtime-library-control.plugin.js'),
|
|
28
|
-
]
|
|
29
|
-
: [
|
|
30
|
-
...((_c = configOverride === null || configOverride === void 0 ? void 0 : configOverride.runtimePlugins) !== null && _c !== void 0 ? _c : []),
|
|
31
|
-
require.resolve('@module-federation/node/runtimePlugin'),
|
|
32
|
-
], virtualRuntimeEntry: true }), {}), sharedLibraries.getReplacementPlugin());
|
|
33
|
-
// The env var is only set from the module-federation-dev-server
|
|
34
|
-
// Attach the runtime plugin
|
|
35
|
-
config.plugins.push(new core_1.DefinePlugin({
|
|
36
|
-
'process.env.NX_MF_DEV_REMOTES': process.env.NX_MF_DEV_REMOTES,
|
|
37
|
-
}));
|
|
38
|
-
return config;
|
|
39
|
-
};
|
|
6
|
+
async function withModuleFederationForSSR(options, configOverride) {
|
|
7
|
+
if (global.NX_GRAPH_CREATION) {
|
|
8
|
+
return (config) => config;
|
|
9
|
+
}
|
|
10
|
+
const { sharedLibraries, sharedDependencies, mappedRemotes } = await (0, utils_1.getModuleFederationConfig)(options, {
|
|
11
|
+
isServer: true,
|
|
40
12
|
});
|
|
13
|
+
return (config, { context }) => {
|
|
14
|
+
config.target = 'async-node';
|
|
15
|
+
config.output.uniqueName = options.name;
|
|
16
|
+
config.optimization = {
|
|
17
|
+
...(config.optimization ?? {}),
|
|
18
|
+
runtimeChunk: false,
|
|
19
|
+
};
|
|
20
|
+
config.plugins.push(
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
22
|
+
new (require('@module-federation/enhanced/rspack').ModuleFederationPlugin)({
|
|
23
|
+
name: options.name,
|
|
24
|
+
filename: 'remoteEntry.js',
|
|
25
|
+
exposes: options.exposes,
|
|
26
|
+
remotes: mappedRemotes,
|
|
27
|
+
shared: {
|
|
28
|
+
...sharedDependencies,
|
|
29
|
+
},
|
|
30
|
+
isServer: true,
|
|
31
|
+
/**
|
|
32
|
+
* Apply user-defined config overrides
|
|
33
|
+
*/
|
|
34
|
+
...(configOverride ? configOverride : {}),
|
|
35
|
+
runtimePlugins: process.env.NX_MF_DEV_REMOTES &&
|
|
36
|
+
!options.disableNxRuntimeLibraryControlPlugin
|
|
37
|
+
? [
|
|
38
|
+
...(configOverride?.runtimePlugins ?? []),
|
|
39
|
+
require.resolve('@module-federation/node/runtimePlugin'),
|
|
40
|
+
require.resolve('@nx/rspack/src/utils/module-federation/plugins/runtime-library-control.plugin.js'),
|
|
41
|
+
]
|
|
42
|
+
: [
|
|
43
|
+
...(configOverride?.runtimePlugins ?? []),
|
|
44
|
+
require.resolve('@module-federation/node/runtimePlugin'),
|
|
45
|
+
],
|
|
46
|
+
virtualRuntimeEntry: true,
|
|
47
|
+
}, {}), sharedLibraries.getReplacementPlugin());
|
|
48
|
+
// The env var is only set from the module-federation-dev-server
|
|
49
|
+
// Attach the runtime plugin
|
|
50
|
+
config.plugins.push(new core_1.DefinePlugin({
|
|
51
|
+
'process.env.NX_MF_DEV_REMOTES': process.env.NX_MF_DEV_REMOTES,
|
|
52
|
+
}));
|
|
53
|
+
return config;
|
|
54
|
+
};
|
|
41
55
|
}
|
|
42
|
-
//# sourceMappingURL=with-module-federation-ssr.js.map
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.withModuleFederation = withModuleFederation;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const rspack_1 = require("@module-federation/enhanced/rspack");
|
|
6
5
|
const core_1 = require("@rspack/core");
|
|
7
6
|
const utils_1 = require("./utils");
|
|
@@ -10,43 +9,62 @@ const isVarOrWindow = (libType) => libType === 'var' || libType === 'window';
|
|
|
10
9
|
* @param {ModuleFederationConfig} options
|
|
11
10
|
* @param {NxModuleFederationConfigOverride} configOverride
|
|
12
11
|
*/
|
|
13
|
-
function withModuleFederation(options, configOverride) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if (global.NX_GRAPH_CREATION) {
|
|
17
|
-
return function makeConfig(config) {
|
|
18
|
-
return config;
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
const { sharedDependencies, sharedLibraries, mappedRemotes } = yield (0, utils_1.getModuleFederationConfig)(options);
|
|
22
|
-
const isGlobal = isVarOrWindow((_a = options.library) === null || _a === void 0 ? void 0 : _a.type);
|
|
23
|
-
return function makeConfig(config, { context }) {
|
|
24
|
-
var _a, _b;
|
|
25
|
-
config.output.uniqueName = options.name;
|
|
26
|
-
config.output.publicPath = 'auto';
|
|
27
|
-
if (isGlobal) {
|
|
28
|
-
config.output.scriptType = 'text/javascript';
|
|
29
|
-
}
|
|
30
|
-
config.optimization = Object.assign(Object.assign({}, ((_a = config.optimization) !== null && _a !== void 0 ? _a : {})), { runtimeChunk: false });
|
|
31
|
-
if (config.mode === 'development' &&
|
|
32
|
-
Object.keys(mappedRemotes).length > 1 &&
|
|
33
|
-
!options.exposes) {
|
|
34
|
-
config.optimization.runtimeChunk = 'single';
|
|
35
|
-
}
|
|
36
|
-
config.plugins.push(new rspack_1.ModuleFederationPlugin(Object.assign(Object.assign(Object.assign({ name: options.name, filename: 'remoteEntry.js', exposes: options.exposes, remotes: mappedRemotes, shared: Object.assign({}, sharedDependencies) }, (isGlobal ? { remoteType: 'script' } : {})), (configOverride ? configOverride : {})), { runtimePlugins: process.env.NX_MF_DEV_REMOTES &&
|
|
37
|
-
!options.disableNxRuntimeLibraryControlPlugin
|
|
38
|
-
? [
|
|
39
|
-
...((_b = configOverride === null || configOverride === void 0 ? void 0 : configOverride.runtimePlugins) !== null && _b !== void 0 ? _b : []),
|
|
40
|
-
require.resolve('@nx/rspack/src/utils/module-federation/plugins/runtime-library-control.plugin.js'),
|
|
41
|
-
]
|
|
42
|
-
: configOverride === null || configOverride === void 0 ? void 0 : configOverride.runtimePlugins, virtualRuntimeEntry: true })), sharedLibraries.getReplacementPlugin());
|
|
43
|
-
// The env var is only set from the module-federation-dev-server
|
|
44
|
-
// Attach the runtime plugin
|
|
45
|
-
config.plugins.push(new core_1.DefinePlugin({
|
|
46
|
-
'process.env.NX_MF_DEV_REMOTES': process.env.NX_MF_DEV_REMOTES,
|
|
47
|
-
}));
|
|
12
|
+
async function withModuleFederation(options, configOverride) {
|
|
13
|
+
if (global.NX_GRAPH_CREATION) {
|
|
14
|
+
return function makeConfig(config) {
|
|
48
15
|
return config;
|
|
49
16
|
};
|
|
50
|
-
}
|
|
17
|
+
}
|
|
18
|
+
const { sharedDependencies, sharedLibraries, mappedRemotes } = await (0, utils_1.getModuleFederationConfig)(options);
|
|
19
|
+
const isGlobal = isVarOrWindow(options.library?.type);
|
|
20
|
+
return function makeConfig(config, { context }) {
|
|
21
|
+
config.output.uniqueName = options.name;
|
|
22
|
+
config.output.publicPath = 'auto';
|
|
23
|
+
if (isGlobal) {
|
|
24
|
+
config.output.scriptType = 'text/javascript';
|
|
25
|
+
}
|
|
26
|
+
config.optimization = {
|
|
27
|
+
...(config.optimization ?? {}),
|
|
28
|
+
runtimeChunk: false,
|
|
29
|
+
};
|
|
30
|
+
if (config.mode === 'development' &&
|
|
31
|
+
Object.keys(mappedRemotes).length > 1 &&
|
|
32
|
+
!options.exposes) {
|
|
33
|
+
config.optimization.runtimeChunk = 'single';
|
|
34
|
+
}
|
|
35
|
+
config.plugins.push(new rspack_1.ModuleFederationPlugin({
|
|
36
|
+
name: options.name,
|
|
37
|
+
filename: 'remoteEntry.js',
|
|
38
|
+
exposes: options.exposes,
|
|
39
|
+
remotes: mappedRemotes,
|
|
40
|
+
shared: {
|
|
41
|
+
...sharedDependencies,
|
|
42
|
+
},
|
|
43
|
+
/**
|
|
44
|
+
* remoteType: 'script' is required for the remote to be loaded as a script tag.
|
|
45
|
+
* remotes will need to be defined as:
|
|
46
|
+
* { appX: 'appX@http://localhost:3001/remoteEntry.js' }
|
|
47
|
+
* { appY: 'appY@http://localhost:3002/remoteEntry.js' }
|
|
48
|
+
*/
|
|
49
|
+
...(isGlobal ? { remoteType: 'script' } : {}),
|
|
50
|
+
/**
|
|
51
|
+
* Apply user-defined config overrides
|
|
52
|
+
*/
|
|
53
|
+
...(configOverride ? configOverride : {}),
|
|
54
|
+
runtimePlugins: process.env.NX_MF_DEV_REMOTES &&
|
|
55
|
+
!options.disableNxRuntimeLibraryControlPlugin
|
|
56
|
+
? [
|
|
57
|
+
...(configOverride?.runtimePlugins ?? []),
|
|
58
|
+
require.resolve('@nx/rspack/src/utils/module-federation/plugins/runtime-library-control.plugin.js'),
|
|
59
|
+
]
|
|
60
|
+
: configOverride?.runtimePlugins,
|
|
61
|
+
virtualRuntimeEntry: true,
|
|
62
|
+
}), sharedLibraries.getReplacementPlugin());
|
|
63
|
+
// The env var is only set from the module-federation-dev-server
|
|
64
|
+
// Attach the runtime plugin
|
|
65
|
+
config.plugins.push(new core_1.DefinePlugin({
|
|
66
|
+
'process.env.NX_MF_DEV_REMOTES': process.env.NX_MF_DEV_REMOTES,
|
|
67
|
+
}));
|
|
68
|
+
return config;
|
|
69
|
+
};
|
|
51
70
|
}
|
|
52
|
-
//# sourceMappingURL=with-module-federation.js.map
|
|
@@ -31,10 +31,12 @@ function normalizeAssets(assets, root, sourceRoot) {
|
|
|
31
31
|
}
|
|
32
32
|
const assetPath = (0, devkit_1.normalizePath)(asset.input);
|
|
33
33
|
const resolvedAssetPath = (0, path_1.resolve)(root, assetPath);
|
|
34
|
-
return
|
|
34
|
+
return {
|
|
35
|
+
...asset,
|
|
36
|
+
input: resolvedAssetPath,
|
|
35
37
|
// Now we remove starting slash to make Webpack place it from the output root.
|
|
36
|
-
output: asset.output.replace(/^\//, '')
|
|
38
|
+
output: asset.output.replace(/^\//, ''),
|
|
39
|
+
};
|
|
37
40
|
}
|
|
38
41
|
});
|
|
39
42
|
}
|
|
40
|
-
//# sourceMappingURL=normalize-assets.js.map
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.readRspackOptions = readRspackOptions;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const devkit_1 = require("@nx/devkit");
|
|
6
5
|
const config_1 = require("./config");
|
|
7
6
|
/**
|
|
@@ -12,30 +11,27 @@ const config_1 = require("./config");
|
|
|
12
11
|
*
|
|
13
12
|
* @param rspackConfig
|
|
14
13
|
*/
|
|
15
|
-
function readRspackOptions(rspackConfig) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return config;
|
|
39
|
-
});
|
|
14
|
+
async function readRspackOptions(rspackConfig) {
|
|
15
|
+
let config;
|
|
16
|
+
if ((0, config_1.isNxRspackComposablePlugin)(rspackConfig)) {
|
|
17
|
+
config = await rspackConfig({}, {
|
|
18
|
+
// These values are only used during build-time, so passing stubs here just to read out
|
|
19
|
+
// the returned config object.
|
|
20
|
+
options: {
|
|
21
|
+
root: devkit_1.workspaceRoot,
|
|
22
|
+
projectRoot: '',
|
|
23
|
+
sourceRoot: '',
|
|
24
|
+
},
|
|
25
|
+
context: { root: devkit_1.workspaceRoot, cwd: undefined, isVerbose: false },
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
else if (typeof rspackConfig === 'function') {
|
|
29
|
+
config = await rspackConfig({
|
|
30
|
+
production: true, // we want the production build options
|
|
31
|
+
}, {});
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
config = rspackConfig;
|
|
35
|
+
}
|
|
36
|
+
return config;
|
|
40
37
|
}
|
|
41
|
-
//# sourceMappingURL=read-rspack-options.js.map
|
package/src/utils/versions.js
CHANGED