@nx/rspack 20.2.0-beta.1 → 20.2.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/app-plugin.d.ts +2 -0
- package/app-plugin.js +5 -0
- package/generators.json +10 -0
- package/migrations.json +21 -1
- package/module-federation.d.ts +4 -1
- package/module-federation.js +7 -2
- package/package.json +10 -8
- package/react-plugin.d.ts +1 -0
- package/react-plugin.js +5 -0
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +5 -7
- package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js +5 -7
- package/src/executors/module-federation-static-server/module-federation-static-server.impl.d.ts +1 -1
- package/src/executors/module-federation-static-server/module-federation-static-server.impl.js +4 -5
- package/src/executors/rspack/lib/config.d.ts +6 -0
- package/src/executors/rspack/lib/config.js +39 -0
- package/src/executors/rspack/rspack.impl.js +11 -12
- package/src/executors/rspack/schema.d.ts +39 -18
- package/src/executors/rspack/schema.json +191 -0
- package/src/generators/convert-config-to-rspack-plugin/convert-config-to-rspack-plugin.d.ts +7 -0
- package/src/generators/convert-config-to-rspack-plugin/convert-config-to-rspack-plugin.js +92 -0
- package/src/generators/convert-config-to-rspack-plugin/lib/extract-rspack-options.d.ts +6 -0
- package/src/generators/convert-config-to-rspack-plugin/lib/extract-rspack-options.js +106 -0
- package/src/generators/convert-config-to-rspack-plugin/lib/normalize-path-options.d.ts +2 -0
- package/src/generators/convert-config-to-rspack-plugin/lib/normalize-path-options.js +73 -0
- package/src/generators/convert-config-to-rspack-plugin/lib/utils.d.ts +1 -0
- package/src/generators/convert-config-to-rspack-plugin/lib/utils.js +13 -0
- package/src/generators/convert-config-to-rspack-plugin/lib/validate-project.d.ts +9 -0
- package/src/generators/convert-config-to-rspack-plugin/lib/validate-project.js +40 -0
- package/src/generators/convert-config-to-rspack-plugin/schema.json +19 -0
- package/src/generators/convert-to-inferred/__snapshots__/convert-to-inferred.spec.ts.snap +268 -0
- package/src/generators/convert-to-inferred/convert-to-inferred.d.ts +12 -0
- package/src/generators/convert-to-inferred/convert-to-inferred.js +114 -0
- package/src/generators/convert-to-inferred/schema.json +19 -0
- package/src/generators/convert-to-inferred/utils/ast.d.ts +3 -0
- package/src/generators/convert-to-inferred/utils/ast.js +40 -0
- package/src/generators/convert-to-inferred/utils/build-post-target-transformer.d.ts +6 -0
- package/src/generators/convert-to-inferred/utils/build-post-target-transformer.js +210 -0
- package/src/generators/convert-to-inferred/utils/index.d.ts +3 -0
- package/src/generators/convert-to-inferred/utils/index.js +6 -0
- package/src/generators/convert-to-inferred/utils/serve-post-target-transformer.d.ts +6 -0
- package/src/generators/convert-to-inferred/utils/serve-post-target-transformer.js +207 -0
- package/src/generators/convert-to-inferred/utils/types.d.ts +11 -0
- package/src/generators/convert-webpack/lib/transform-cjs.js +5 -5
- package/src/generators/convert-webpack/lib/transform-esm.js +5 -5
- package/src/index.d.ts +1 -0
- package/src/index.js +1 -0
- package/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.d.ts +2 -0
- package/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.js +35 -0
- package/src/plugins/nx-app-rspack-plugin/nx-app-rspack-plugin.d.ts +16 -0
- package/src/plugins/nx-app-rspack-plugin/nx-app-rspack-plugin.js +43 -0
- package/src/plugins/nx-react-rspack-plugin/nx-react-rspack-plugin.d.ts +8 -0
- package/src/plugins/nx-react-rspack-plugin/nx-react-rspack-plugin.js +13 -0
- package/src/plugins/use-legacy-nx-plugin/use-legacy-nx-plugin.d.ts +31 -0
- package/src/plugins/use-legacy-nx-plugin/use-legacy-nx-plugin.js +73 -0
- package/src/plugins/utils/apply-base-config.js +2 -5
- package/src/plugins/utils/apply-web-config.d.ts +2 -2
- package/src/plugins/utils/apply-web-config.js +1 -8
- package/src/plugins/utils/models.d.ts +2 -2
- package/src/plugins/utils/plugins/normalize-options.js +1 -1
- package/src/plugins/utils/plugins/nx-tsconfig-paths-rspack-plugin.js +3 -2
- package/src/utils/create-compiler.d.ts +2 -2
- package/src/utils/create-compiler.js +12 -49
- package/src/utils/generator-utils.d.ts +2 -2
- package/src/utils/generator-utils.js +134 -67
- package/src/utils/has-plugin.d.ts +2 -0
- package/src/utils/has-plugin.js +10 -0
- package/src/utils/module-federation/build-static.remotes.d.ts +1 -1
- package/src/utils/versions.d.ts +2 -2
- package/src/utils/versions.js +2 -2
- package/src/utils/module-federation/dependencies.d.ts +0 -6
- package/src/utils/module-federation/dependencies.js +0 -56
- package/src/utils/module-federation/get-remotes-for-host.d.ts +0 -16
- package/src/utils/module-federation/get-remotes-for-host.js +0 -99
- package/src/utils/module-federation/index.d.ts +0 -6
- package/src/utils/module-federation/index.js +0 -9
- package/src/utils/module-federation/models/index.d.ts +0 -47
- package/src/utils/module-federation/package-json.d.ts +0 -8
- package/src/utils/module-federation/package-json.js +0 -12
- package/src/utils/module-federation/parse-static-remotes-config.d.ts +0 -13
- package/src/utils/module-federation/parse-static-remotes-config.js +0 -34
- package/src/utils/module-federation/plugins/runtime-library-control.plugin.d.ts +0 -3
- package/src/utils/module-federation/plugins/runtime-library-control.plugin.js +0 -54
- package/src/utils/module-federation/public-api.d.ts +0 -8
- package/src/utils/module-federation/public-api.js +0 -20
- package/src/utils/module-federation/remotes.d.ts +0 -19
- package/src/utils/module-federation/remotes.js +0 -85
- package/src/utils/module-federation/secondary-entry-points.d.ts +0 -12
- package/src/utils/module-federation/secondary-entry-points.js +0 -104
- package/src/utils/module-federation/share.d.ts +0 -48
- package/src/utils/module-federation/share.js +0 -235
- package/src/utils/module-federation/start-remote-proxies.d.ts +0 -5
- package/src/utils/module-federation/start-remote-proxies.js +0 -45
- package/src/utils/module-federation/start-ssr-remote-proxies.d.ts +0 -5
- package/src/utils/module-federation/start-ssr-remote-proxies.js +0 -59
- package/src/utils/module-federation/typescript.d.ts +0 -4
- package/src/utils/module-federation/typescript.js +0 -53
- package/src/utils/module-federation/with-module-federation/package-json.d.ts +0 -8
- package/src/utils/module-federation/with-module-federation/package-json.js +0 -12
- package/src/utils/module-federation/with-module-federation/utils.d.ts +0 -12
- package/src/utils/module-federation/with-module-federation/utils.js +0 -76
- package/src/utils/module-federation/with-module-federation/with-module-federation-ssr.d.ts +0 -3
- package/src/utils/module-federation/with-module-federation/with-module-federation-ssr.js +0 -55
- package/src/utils/module-federation/with-module-federation/with-module-federation.d.ts +0 -8
- package/src/utils/module-federation/with-module-federation/with-module-federation.js +0 -70
- /package/src/{utils/module-federation/models/index.js → generators/convert-to-inferred/utils/types.js} +0 -0
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { ParsedCommandLine } from 'typescript';
|
|
2
|
-
export declare function readTsPathMappings(tsConfigPath?: string): ParsedCommandLine['options']['paths'];
|
|
3
|
-
export declare function readTsConfig(tsConfigPath: string): ParsedCommandLine;
|
|
4
|
-
export declare function getRootTsConfigPath(): string | null;
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.readTsPathMappings = readTsPathMappings;
|
|
4
|
-
exports.readTsConfig = readTsConfig;
|
|
5
|
-
exports.getRootTsConfigPath = getRootTsConfigPath;
|
|
6
|
-
const fs_1 = require("fs");
|
|
7
|
-
const path_1 = require("path");
|
|
8
|
-
const devkit_1 = require("@nx/devkit");
|
|
9
|
-
const tsConfig = new Map();
|
|
10
|
-
const tsPathMappings = new Map();
|
|
11
|
-
function readTsPathMappings(tsConfigPath = process.env.NX_TSCONFIG_PATH ?? getRootTsConfigPath()) {
|
|
12
|
-
if (tsPathMappings.has(tsConfigPath)) {
|
|
13
|
-
return tsPathMappings.get(tsConfigPath);
|
|
14
|
-
}
|
|
15
|
-
if (!tsConfig.has(tsConfigPath)) {
|
|
16
|
-
tsConfig.set(tsConfigPath, readTsConfiguration(tsConfigPath));
|
|
17
|
-
}
|
|
18
|
-
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
|
-
});
|
|
24
|
-
});
|
|
25
|
-
return tsPathMappings.get(tsConfigPath);
|
|
26
|
-
}
|
|
27
|
-
function readTsConfiguration(tsConfigPath) {
|
|
28
|
-
if (!(0, fs_1.existsSync)(tsConfigPath)) {
|
|
29
|
-
throw new Error(`NX MF: TsConfig Path for workspace libraries does not exist! (${tsConfigPath}).`);
|
|
30
|
-
}
|
|
31
|
-
return readTsConfig(tsConfigPath);
|
|
32
|
-
}
|
|
33
|
-
let tsModule;
|
|
34
|
-
function readTsConfig(tsConfigPath) {
|
|
35
|
-
if (!tsModule) {
|
|
36
|
-
tsModule = require('typescript');
|
|
37
|
-
}
|
|
38
|
-
const readResult = tsModule.readConfigFile(tsConfigPath, tsModule.sys.readFile);
|
|
39
|
-
return tsModule.parseJsonConfigFileContent(readResult.config, tsModule.sys, (0, path_1.dirname)(tsConfigPath));
|
|
40
|
-
}
|
|
41
|
-
function getRootTsConfigPath() {
|
|
42
|
-
const tsConfigFileName = getRootTsConfigFileName();
|
|
43
|
-
return tsConfigFileName ? (0, path_1.join)(devkit_1.workspaceRoot, tsConfigFileName) : null;
|
|
44
|
-
}
|
|
45
|
-
function getRootTsConfigFileName() {
|
|
46
|
-
for (const tsConfigName of ['tsconfig.base.json', 'tsconfig.json']) {
|
|
47
|
-
const tsConfigPath = (0, path_1.join)(devkit_1.workspaceRoot, tsConfigName);
|
|
48
|
-
if ((0, fs_1.existsSync)(tsConfigPath)) {
|
|
49
|
-
return tsConfigName;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.readRootPackageJson = readRootPackageJson;
|
|
4
|
-
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const fs_1 = require("fs");
|
|
6
|
-
function readRootPackageJson() {
|
|
7
|
-
const pkgJsonPath = (0, devkit_1.joinPathFragments)(devkit_1.workspaceRoot, 'package.json');
|
|
8
|
-
if (!(0, fs_1.existsSync)(pkgJsonPath)) {
|
|
9
|
-
throw new Error('NX MFE: Could not find root package.json to determine dependency versions.');
|
|
10
|
-
}
|
|
11
|
-
return (0, devkit_1.readJsonFile)(pkgJsonPath);
|
|
12
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { ModuleFederationConfig } from '../models';
|
|
2
|
-
export declare function getFunctionDeterminateRemoteUrl(isServer?: boolean): (remote: string) => string;
|
|
3
|
-
export declare function getModuleFederationConfig(mfConfig: ModuleFederationConfig, options?: {
|
|
4
|
-
isServer: boolean;
|
|
5
|
-
determineRemoteUrl?: (remote: string) => string;
|
|
6
|
-
}): Promise<{
|
|
7
|
-
sharedLibraries: import("../models").SharedWorkspaceLibraryConfig;
|
|
8
|
-
sharedDependencies: {
|
|
9
|
-
[x: string]: import("../models").SharedLibraryConfig;
|
|
10
|
-
};
|
|
11
|
-
mappedRemotes: {};
|
|
12
|
-
}>;
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getFunctionDeterminateRemoteUrl = getFunctionDeterminateRemoteUrl;
|
|
4
|
-
exports.getModuleFederationConfig = getModuleFederationConfig;
|
|
5
|
-
const devkit_1 = require("@nx/devkit");
|
|
6
|
-
const project_graph_1 = require("nx/src/project-graph/project-graph");
|
|
7
|
-
const dependencies_1 = require("../dependencies");
|
|
8
|
-
const remotes_1 = require("../remotes");
|
|
9
|
-
const share_1 = require("../share");
|
|
10
|
-
function getFunctionDeterminateRemoteUrl(isServer = false) {
|
|
11
|
-
const target = 'serve';
|
|
12
|
-
const remoteEntry = isServer ? 'server/remoteEntry.js' : 'remoteEntry.js';
|
|
13
|
-
return function (remote) {
|
|
14
|
-
const mappedStaticRemotesFromEnv = process.env
|
|
15
|
-
.NX_MF_DEV_SERVER_STATIC_REMOTES
|
|
16
|
-
? JSON.parse(process.env.NX_MF_DEV_SERVER_STATIC_REMOTES)
|
|
17
|
-
: undefined;
|
|
18
|
-
if (mappedStaticRemotesFromEnv && mappedStaticRemotesFromEnv[remote]) {
|
|
19
|
-
return `${mappedStaticRemotesFromEnv[remote]}/${remoteEntry}`;
|
|
20
|
-
}
|
|
21
|
-
let remoteConfiguration = null;
|
|
22
|
-
try {
|
|
23
|
-
remoteConfiguration = (0, project_graph_1.readCachedProjectConfiguration)(remote);
|
|
24
|
-
}
|
|
25
|
-
catch (e) {
|
|
26
|
-
throw new Error(`Cannot find remote: "${remote}". Check that the remote name is correct in your module federation config file.\n`);
|
|
27
|
-
}
|
|
28
|
-
const serveTarget = remoteConfiguration?.targets?.[target];
|
|
29
|
-
if (!serveTarget) {
|
|
30
|
-
throw new Error(`Cannot automatically determine URL of remote (${remote}). Looked for property "host" in the project's "${serveTarget}" target.\n
|
|
31
|
-
You can also use the tuple syntax in your rspack config to configure your remotes. e.g. \`remotes: [['remote1', 'http://localhost:4201']]\``);
|
|
32
|
-
}
|
|
33
|
-
const host = serveTarget.options?.host ??
|
|
34
|
-
`http${serveTarget.options.ssl ? 's' : ''}://localhost`;
|
|
35
|
-
const port = serveTarget.options?.port ?? 4201;
|
|
36
|
-
return `${host.endsWith('/') ? host.slice(0, -1) : host}:${port}/${remoteEntry}`;
|
|
37
|
-
};
|
|
38
|
-
}
|
|
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 };
|
|
76
|
-
}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { ModuleFederationConfig, NxModuleFederationConfigOverride } from '../models';
|
|
2
|
-
import { NxRspackExecutionContext } from '../../config';
|
|
3
|
-
export declare function withModuleFederationForSSR(options: ModuleFederationConfig, configOverride?: NxModuleFederationConfigOverride): Promise<(config: any, { context }: NxRspackExecutionContext) => any>;
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.withModuleFederationForSSR = withModuleFederationForSSR;
|
|
4
|
-
const core_1 = require("@rspack/core");
|
|
5
|
-
const utils_1 = require("./utils");
|
|
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,
|
|
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.replace(/-/g, '_'),
|
|
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
|
-
};
|
|
55
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { Configuration } from '@rspack/core';
|
|
2
|
-
import { ModuleFederationConfig, NxModuleFederationConfigOverride } from '../models';
|
|
3
|
-
import { NxRspackExecutionContext } from '../../config';
|
|
4
|
-
/**
|
|
5
|
-
* @param {ModuleFederationConfig} options
|
|
6
|
-
* @param {NxModuleFederationConfigOverride} configOverride
|
|
7
|
-
*/
|
|
8
|
-
export declare function withModuleFederation(options: ModuleFederationConfig, configOverride?: NxModuleFederationConfigOverride): Promise<(config: Configuration, { context }: NxRspackExecutionContext) => Configuration>;
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.withModuleFederation = withModuleFederation;
|
|
4
|
-
const rspack_1 = require("@module-federation/enhanced/rspack");
|
|
5
|
-
const core_1 = require("@rspack/core");
|
|
6
|
-
const utils_1 = require("./utils");
|
|
7
|
-
const isVarOrWindow = (libType) => libType === 'var' || libType === 'window';
|
|
8
|
-
/**
|
|
9
|
-
* @param {ModuleFederationConfig} options
|
|
10
|
-
* @param {NxModuleFederationConfigOverride} configOverride
|
|
11
|
-
*/
|
|
12
|
-
async function withModuleFederation(options, configOverride) {
|
|
13
|
-
if (global.NX_GRAPH_CREATION) {
|
|
14
|
-
return function makeConfig(config) {
|
|
15
|
-
return config;
|
|
16
|
-
};
|
|
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.replace(/-/g, '_'),
|
|
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
|
-
};
|
|
70
|
-
}
|
|
File without changes
|