Project Init

This commit is contained in:
Muluhabt
2026-05-29 15:23:46 +03:00
commit 2fbc557aac
67387 changed files with 6063341 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
import { ModuleFederationConfig, SharedLibraryConfig } from '../../utils';
/**
* Default npm packages to always share for Angular projects.
*/
export declare const DEFAULT_ANGULAR_PACKAGES_TO_SHARE: string[];
/**
* npm packages to avoid sharing in Angular projects.
*/
export declare const DEFAULT_NPM_PACKAGES_TO_AVOID: string[];
/**
* Applies eager loading to default Angular packages.
* Exported for backward compatibility.
*/
export declare function applyDefaultEagerPackages(sharedConfig: Record<string, SharedLibraryConfig>, useRspack?: boolean): void;
/**
* Creates the default remote URL resolver for Angular.
* Kept for backward compatibility with existing configs.
*/
export declare function getFunctionDeterminateRemoteUrl(isServer?: boolean, useRspack?: boolean): (remote: string) => string;
export declare function getModuleFederationConfig(mfConfig: ModuleFederationConfig, options?: {
isServer: boolean;
determineRemoteUrl?: (remote: string) => string;
}, bundler?: 'rspack' | 'webpack'): Promise<import("../../utils/module-federation-config").ModuleFederationConfigResult>;
export declare function getModuleFederationConfigSync(mfConfig: ModuleFederationConfig, options?: {
isServer: boolean;
determineRemoteUrl?: (remote: string) => string;
}, useRspack?: boolean): import("../../utils/module-federation-config").ModuleFederationConfigResult;
//# sourceMappingURL=utils.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../../packages/module-federation/src/with-module-federation/angular/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAQ1E;;GAEG;AACH,eAAO,MAAM,iCAAiC,UAI7C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,6BAA6B,UAKzC,CAAC;AAEF;;;GAGG;AACH,wBAAgB,yBAAyB,CACvC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,EACjD,SAAS,UAAQ,QAwBlB;AAED;;;GAGG;AACH,wBAAgB,+BAA+B,CAC7C,QAAQ,GAAE,OAAe,EACzB,SAAS,UAAQ,8BAGlB;AAqBD,wBAAsB,yBAAyB,CAC7C,QAAQ,EAAE,sBAAsB,EAChC,OAAO,GAAE;IACP,QAAQ,EAAE,OAAO,CAAC;IAClB,kBAAkB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC;CAC3B,EACvB,OAAO,GAAE,QAAQ,GAAG,SAAoB,wFAQzC;AAED,wBAAgB,6BAA6B,CAC3C,QAAQ,EAAE,sBAAsB,EAChC,OAAO,GAAE;IACP,QAAQ,EAAE,OAAO,CAAC;IAClB,kBAAkB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC;CAC3B,EACvB,SAAS,UAAQ,+EAOlB"}

View File

@@ -0,0 +1,82 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DEFAULT_NPM_PACKAGES_TO_AVOID = exports.DEFAULT_ANGULAR_PACKAGES_TO_SHARE = void 0;
exports.applyDefaultEagerPackages = applyDefaultEagerPackages;
exports.getFunctionDeterminateRemoteUrl = getFunctionDeterminateRemoteUrl;
exports.getModuleFederationConfig = getModuleFederationConfig;
exports.getModuleFederationConfigSync = getModuleFederationConfigSync;
const module_federation_config_1 = require("../../utils/module-federation-config");
/**
* Default npm packages to always share for Angular projects.
*/
exports.DEFAULT_ANGULAR_PACKAGES_TO_SHARE = [
'@angular/core',
'@angular/animations',
'@angular/common',
];
/**
* npm packages to avoid sharing in Angular projects.
*/
exports.DEFAULT_NPM_PACKAGES_TO_AVOID = [
'zone.js',
'@nx/angular/mf',
'@nrwl/angular/mf',
'@nx/angular-rspack',
];
/**
* Applies eager loading to default Angular packages.
* Exported for backward compatibility.
*/
function applyDefaultEagerPackages(sharedConfig, useRspack = false) {
const DEFAULT_PACKAGES_TO_LOAD_EAGERLY = [
'@angular/localize',
'@angular/localize/init',
...(useRspack
? [
'@angular/core',
'@angular/core/primitives/signals',
'@angular/core/primitives/di',
'@angular/core/event-dispatch',
'@angular/core/rxjs-interop',
'@angular/common',
'@angular/common/http',
'@angular/platform-browser',
]
: []),
];
for (const pkg of DEFAULT_PACKAGES_TO_LOAD_EAGERLY) {
if (!sharedConfig[pkg]) {
continue;
}
sharedConfig[pkg] = { ...sharedConfig[pkg], eager: true };
}
}
/**
* Creates the default remote URL resolver for Angular.
* Kept for backward compatibility with existing configs.
*/
function getFunctionDeterminateRemoteUrl(isServer = false, useRspack = false) {
return (0, module_federation_config_1.createDefaultRemoteUrlResolver)(isServer, useRspack ? 'js' : 'mjs');
}
/**
* Creates framework config for Angular projects.
*/
function getAngularFrameworkConfig(bundler, useRspack) {
return {
bundler,
remoteEntryExt: useRspack ? 'js' : 'mjs',
mapRemotesExpose: false,
defaultPackagesToShare: exports.DEFAULT_ANGULAR_PACKAGES_TO_SHARE,
packagesToAvoid: exports.DEFAULT_NPM_PACKAGES_TO_AVOID,
applyEagerPackages: (sharedConfig) => {
applyDefaultEagerPackages(sharedConfig, useRspack);
},
};
}
async function getModuleFederationConfig(mfConfig, options = { isServer: false }, bundler = 'rspack') {
// Angular async uses 'mjs' extension (webpack), not rspack
return (0, module_federation_config_1.getModuleFederationConfigAsync)(mfConfig, options, getAngularFrameworkConfig(bundler, false));
}
function getModuleFederationConfigSync(mfConfig, options = { isServer: false }, useRspack = false) {
return (0, module_federation_config_1.getModuleFederationConfigSync)(mfConfig, options, getAngularFrameworkConfig('rspack', useRspack));
}

View File

@@ -0,0 +1,3 @@
import { type ModuleFederationConfig, type NxModuleFederationConfigOverride } from '../../utils';
export declare function withModuleFederationForSSR(options: ModuleFederationConfig, configOverride?: NxModuleFederationConfigOverride): Promise<(config: any) => any>;
//# sourceMappingURL=with-module-federation-ssr.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"with-module-federation-ssr.d.ts","sourceRoot":"","sources":["../../../../../../packages/module-federation/src/with-module-federation/angular/with-module-federation-ssr.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,sBAAsB,EAC3B,KAAK,gCAAgC,EACtC,MAAM,aAAa,CAAC;AAIrB,wBAAsB,0BAA0B,CAC9C,OAAO,EAAE,sBAAsB,EAC/B,cAAc,CAAC,EAAE,gCAAgC,iCAgGlD"}

View File

@@ -0,0 +1,85 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.withModuleFederationForSSR = withModuleFederationForSSR;
const utils_1 = require("../../utils");
const utils_2 = require("./utils");
const devkit_1 = require("@nx/devkit");
async function withModuleFederationForSSR(options, configOverride) {
if (global.NX_GRAPH_CREATION) {
return (config) => config;
}
const isDevServer = process.env['WEBPACK_SERVE'];
const { sharedLibraries, sharedDependencies, mappedRemotes } = await (0, utils_2.getModuleFederationConfig)(options, {
isServer: true,
}, 'webpack');
return (config) => {
const updatedConfig = {
...(config ?? {}),
target: 'async-node',
output: {
...(config.output ?? {}),
uniqueName: options.name,
},
optimization: {
...(config.optimization ?? {}),
runtimeChunk: isDevServer
? (config.optimization?.runtimeChunk ?? undefined)
: false,
},
resolve: {
...(config.resolve ?? {}),
modules: [
...(config.resolve?.modules ?? ['node_modules']),
devkit_1.workspaceRoot,
],
alias: {
...(config.resolve?.alias ?? {}),
...sharedLibraries.getAliases(),
},
},
plugins: [
...(config.plugins ?? []),
new (require('@module-federation/enhanced').ModuleFederationPlugin)({
name: (0, utils_1.normalizeProjectName)(options.name),
filename: 'remoteEntry.js',
exposes: options.exposes,
remotes: mappedRemotes,
shared: {
...sharedDependencies,
},
remoteType: 'script',
library: {
type: 'commonjs-module',
},
/**
* Apply user-defined config override
*/
...(configOverride ? configOverride : {}),
experiments: {
asyncStartup: true,
// We should allow users to override experiments
...(configOverride?.experiments ?? {}),
},
runtimePlugins: process.env.NX_MF_DEV_REMOTES &&
!options.disableNxRuntimeLibraryControlPlugin
? [
...(configOverride?.runtimePlugins ?? []),
require.resolve('@module-federation/node/runtimePlugin'),
require.resolve('@nx/module-federation/src/utils/plugins/runtime-library-control.plugin.js'),
]
: [
...(configOverride?.runtimePlugins ?? []),
require.resolve('@module-federation/node/runtimePlugin'),
],
}, {}),
sharedLibraries.getReplacementPlugin(),
],
};
// The env var is only set from the module-federation-dev-server
// Attach the runtime plugin
updatedConfig.plugins.push(new (require('webpack').DefinePlugin)({
'process.env.NX_MF_DEV_REMOTES': process.env.NX_MF_DEV_REMOTES,
}));
return updatedConfig;
};
}

View File

@@ -0,0 +1,3 @@
import { type ModuleFederationConfig, type NxModuleFederationConfigOverride } from '../../utils';
export declare function withModuleFederation(options: ModuleFederationConfig, configOverride?: NxModuleFederationConfigOverride): Promise<(config: any) => any>;
//# sourceMappingURL=with-module-federation.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"with-module-federation.d.ts","sourceRoot":"","sources":["../../../../../../packages/module-federation/src/with-module-federation/angular/with-module-federation.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,sBAAsB,EAC3B,KAAK,gCAAgC,EACtC,MAAM,aAAa,CAAC;AAKrB,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,sBAAsB,EAC/B,cAAc,CAAC,EAAE,gCAAgC,iCAwFlD"}

View File

@@ -0,0 +1,84 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.withModuleFederation = withModuleFederation;
const utils_1 = require("../../utils");
const utils_2 = require("./utils");
const webpack_1 = require("@module-federation/enhanced/webpack");
const devkit_1 = require("@nx/devkit");
async function withModuleFederation(options, configOverride) {
if (global.NX_GRAPH_CREATION) {
return (config) => config;
}
// This is required to ensure that the webpack version used by the Angular CLI is used
process.env['FEDERATION_WEBPACK_PATH'] = require.resolve('webpack', {
paths: [require.resolve('@angular-devkit/build-angular')],
});
const isDevServer = process.env['WEBPACK_SERVE'];
const { sharedLibraries, sharedDependencies, mappedRemotes } = await (0, utils_2.getModuleFederationConfig)(options, undefined, 'webpack');
return (config) => {
const updatedConfig = {
...(config ?? {}),
output: {
...(config.output ?? {}),
uniqueName: options.name,
publicPath: 'auto',
},
optimization: {
...(config.optimization ?? {}),
runtimeChunk: isDevServer && !options.exposes
? (config.optimization?.runtimeChunk ?? undefined)
: false,
},
resolve: {
...(config.resolve ?? {}),
// Ensure workspace root is in resolve.modules so that expose paths
// like "apps/remote/src/..." resolve correctly without baseUrl.
modules: [
...(config.resolve?.modules ?? ['node_modules']),
devkit_1.workspaceRoot,
],
alias: {
...(config.resolve?.alias ?? {}),
...sharedLibraries.getAliases(),
},
},
experiments: {
...(config.experiments ?? {}),
outputModule: true,
},
plugins: [
...(config.plugins ?? []),
new webpack_1.ModuleFederationPlugin({
name: (0, utils_1.normalizeProjectName)(options.name),
filename: 'remoteEntry.mjs',
exposes: options.exposes,
remotes: mappedRemotes,
shared: {
...sharedDependencies,
},
library: {
type: 'module',
},
/**
* Apply user-defined config override
*/
...(configOverride ? configOverride : {}),
runtimePlugins: process.env.NX_MF_DEV_REMOTES &&
!options.disableNxRuntimeLibraryControlPlugin
? [
...(configOverride?.runtimePlugins ?? []),
require.resolve('@nx/module-federation/src/utils/plugins/runtime-library-control.plugin.js'),
]
: configOverride?.runtimePlugins,
}),
sharedLibraries.getReplacementPlugin(),
],
};
// The env var is only set from the module-federation-dev-server
// Attach the runtime plugin
updatedConfig.plugins.push(new (require('webpack').DefinePlugin)({
'process.env.NX_MF_DEV_REMOTES': process.env.NX_MF_DEV_REMOTES,
}));
return updatedConfig;
};
}

View File

@@ -0,0 +1,3 @@
import type { SharedLibraryConfig } from '../../utils';
export declare function applyDefaultEagerPackages(sharedConfig: Record<string, SharedLibraryConfig>): void;
//# sourceMappingURL=utils.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../../packages/module-federation/src/with-module-federation/react/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEvD,wBAAgB,yBAAyB,CACvC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,QAelD"}

View File

@@ -0,0 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.applyDefaultEagerPackages = applyDefaultEagerPackages;
function applyDefaultEagerPackages(sharedConfig) {
const DEFAULT_REACT_PACKAGES_TO_LOAD_EAGERLY = [
'react',
'react-dom',
'react-router-dom',
'react-router',
];
for (const pkg of DEFAULT_REACT_PACKAGES_TO_LOAD_EAGERLY) {
if (!sharedConfig[pkg]) {
continue;
}
sharedConfig[pkg] = { ...sharedConfig[pkg], eager: true };
}
}

View File

@@ -0,0 +1,11 @@
import { ModuleFederationConfig } from '../../utils';
/**
* Creates the default remote URL resolver for rspack.
* Kept for backward compatibility with existing configs.
*/
export declare function getFunctionDeterminateRemoteUrl(isServer?: boolean): (remote: string) => string;
export declare function getModuleFederationConfig(mfConfig: ModuleFederationConfig, options?: {
isServer: boolean;
determineRemoteUrl?: (remote: string) => string;
}): import("../../utils/module-federation-config").ModuleFederationConfigResult;
//# sourceMappingURL=utils.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../../packages/module-federation/src/with-module-federation/rspack/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAuB,MAAM,aAAa,CAAC;AAU1E;;;GAGG;AACH,wBAAgB,+BAA+B,CAAC,QAAQ,UAAQ,8BAE/D;AAsBD,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,sBAAsB,EAChC,OAAO,GAAE;IACP,QAAQ,EAAE,OAAO,CAAC;IAClB,kBAAkB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC;CAC3B,+EAOxB"}

View File

@@ -0,0 +1,32 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getFunctionDeterminateRemoteUrl = getFunctionDeterminateRemoteUrl;
exports.getModuleFederationConfig = getModuleFederationConfig;
const module_federation_config_1 = require("../../utils/module-federation-config");
const utils_1 = require("../react/utils");
const framework_detection_1 = require("../../utils/framework-detection");
/**
* Creates the default remote URL resolver for rspack.
* Kept for backward compatibility with existing configs.
*/
function getFunctionDeterminateRemoteUrl(isServer = false) {
return (0, module_federation_config_1.createDefaultRemoteUrlResolver)(isServer, 'js');
}
/**
* Framework config for rspack projects (React).
*/
function getRspackFrameworkConfig() {
return {
bundler: 'rspack',
remoteEntryExt: 'js',
mapRemotesExpose: true,
applyEagerPackages: (sharedConfig, projectGraph, projectName) => {
if ((0, framework_detection_1.isReactProject)(projectName, projectGraph)) {
(0, utils_1.applyDefaultEagerPackages)(sharedConfig);
}
},
};
}
function getModuleFederationConfig(mfConfig, options = { isServer: false }) {
return (0, module_federation_config_1.getModuleFederationConfigSync)(mfConfig, options, getRspackFrameworkConfig());
}

View File

@@ -0,0 +1,5 @@
import { ModuleFederationConfig, NxModuleFederationConfigOverride } from '../../utils';
export declare function withModuleFederationForSSR(options: ModuleFederationConfig, configOverride?: NxModuleFederationConfigOverride): Promise<(config: any, { context }: {
context: any;
}) => any>;
//# sourceMappingURL=with-module-federation-ssr.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"with-module-federation-ssr.d.ts","sourceRoot":"","sources":["../../../../../../packages/module-federation/src/with-module-federation/rspack/with-module-federation-ssr.ts"],"names":[],"mappings":"AACA,OAAO,EACL,sBAAsB,EAEtB,gCAAgC,EACjC,MAAM,aAAa,CAAC;AAIrB,wBAAsB,0BAA0B,CAC9C,OAAO,EAAE,sBAAsB,EAC/B,cAAc,CAAC,EAAE,gCAAgC;;WAoFlD"}

View File

@@ -0,0 +1,74 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.withModuleFederationForSSR = withModuleFederationForSSR;
const core_1 = require("@rspack/core");
const utils_1 = require("../../utils");
const utils_2 = require("./utils");
const devkit_1 = require("@nx/devkit");
async function withModuleFederationForSSR(options, configOverride) {
if (global.NX_GRAPH_CREATION) {
return (config) => config;
}
const isDevServer = process.env['WEBPACK_SERVE'];
const { sharedLibraries, sharedDependencies, mappedRemotes } = (0, utils_2.getModuleFederationConfig)(options, {
isServer: true,
});
return (config, { context }) => {
config.target = 'async-node';
config.output.uniqueName = options.name;
config.output.library = {
type: 'commonjs-module',
};
config.resolve ??= {};
config.resolve.modules = [
...(config.resolve.modules ?? ['node_modules']),
devkit_1.workspaceRoot,
];
config.optimization = {
...(config.optimization ?? {}),
runtimeChunk: isDevServer
? (config.optimization?.runtimeChunk ?? undefined)
: false,
};
config.plugins.push(new (require('@module-federation/enhanced/rspack').ModuleFederationPlugin)({
name: (0, utils_1.normalizeProjectName)(options.name),
filename: 'remoteEntry.js',
exposes: options.exposes,
remotes: mappedRemotes,
shared: {
...sharedDependencies,
},
isServer: true,
library: {
type: 'commonjs-module',
},
remoteType: 'script',
/**
* Apply user-defined config overrides
*/
...(configOverride ? configOverride : {}),
experiments: {
asyncStartup: true,
// We should allow users to override experiments
...(configOverride?.experiments ?? {}),
},
runtimePlugins: process.env.NX_MF_DEV_REMOTES &&
!options.disableNxRuntimeLibraryControlPlugin
? [
...(configOverride?.runtimePlugins ?? []),
require.resolve('@module-federation/node/runtimePlugin'),
require.resolve('@nx/module-federation/src/utils/plugins/runtime-library-control.plugin.js'),
]
: [
...(configOverride?.runtimePlugins ?? []),
require.resolve('@module-federation/node/runtimePlugin'),
],
}, {}), sharedLibraries.getReplacementPlugin());
// The env var is only set from the module-federation-dev-server
// Attach the runtime plugin
config.plugins.push(new core_1.DefinePlugin({
'process.env.NX_MF_DEV_REMOTES': process.env.NX_MF_DEV_REMOTES,
}));
return config;
};
}

View File

@@ -0,0 +1,10 @@
import type { Configuration } from '@rspack/core';
import { ModuleFederationConfig, NxModuleFederationConfigOverride } from '../../utils';
/**
* @param {ModuleFederationConfig} options
* @param {NxModuleFederationConfigOverride} configOverride
*/
export declare function withModuleFederation(options: ModuleFederationConfig, configOverride?: NxModuleFederationConfigOverride): Promise<(config: Configuration, { context }: {
context: any;
}) => Configuration>;
//# sourceMappingURL=with-module-federation.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"with-module-federation.d.ts","sourceRoot":"","sources":["../../../../../../packages/module-federation/src/with-module-federation/rspack/with-module-federation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD,OAAO,EACL,sBAAsB,EAEtB,gCAAgC,EACjC,MAAM,aAAa,CAAC;AAOrB;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,sBAAsB,EAC/B,cAAc,CAAC,EAAE,gCAAgC,oBAcvC,aAAa;;MAEpB,aAAa,EAyEjB"}

View File

@@ -0,0 +1,79 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.withModuleFederation = withModuleFederation;
const rspack_1 = require("@module-federation/enhanced/rspack");
const core_1 = require("@rspack/core");
const utils_1 = require("../../utils");
const utils_2 = require("./utils");
const devkit_1 = require("@nx/devkit");
const isVarOrWindow = (libType) => libType === 'var' || libType === 'window';
/**
* @param {ModuleFederationConfig} options
* @param {NxModuleFederationConfigOverride} configOverride
*/
async function withModuleFederation(options, configOverride) {
if (global.NX_GRAPH_CREATION) {
return function makeConfig(config) {
return config;
};
}
const isDevServer = process.env['WEBPACK_SERVE'];
const { sharedDependencies, sharedLibraries, mappedRemotes } = (0, utils_2.getModuleFederationConfig)(options);
const isGlobal = isVarOrWindow(options.library?.type);
return function makeConfig(config, { context }) {
config.output.uniqueName = options.name;
config.output.publicPath = 'auto';
if (isGlobal) {
config.output.scriptType = 'text/javascript';
}
config.resolve ??= {};
config.resolve.modules = [
...(config.resolve.modules ?? ['node_modules']),
devkit_1.workspaceRoot,
];
config.optimization = {
...(config.optimization ?? {}),
runtimeChunk: isDevServer && !options.exposes
? (config.optimization?.runtimeChunk ?? undefined)
: false,
};
if (config.mode === 'development' &&
Object.keys(mappedRemotes).length > 1 &&
!options.exposes) {
config.optimization.runtimeChunk = 'single';
}
config.plugins.push(new rspack_1.ModuleFederationPlugin({
name: (0, utils_1.normalizeProjectName)(options.name),
filename: 'remoteEntry.js',
exposes: options.exposes,
remotes: mappedRemotes,
shared: {
...sharedDependencies,
},
/**
* remoteType: 'script' is required for the remote to be loaded as a script tag.
* remotes will need to be defined as:
* { appX: 'appX@http://localhost:3001/remoteEntry.js' }
* { appY: 'appY@http://localhost:3002/remoteEntry.js' }
*/
...(isGlobal ? { remoteType: 'script' } : {}),
/**
* Apply user-defined config overrides
*/
...(configOverride ? configOverride : {}),
runtimePlugins: process.env.NX_MF_DEV_REMOTES &&
!options.disableNxRuntimeLibraryControlPlugin
? [
...(configOverride?.runtimePlugins ?? []),
require.resolve('@nx/module-federation/src/utils/plugins/runtime-library-control.plugin.js'),
]
: configOverride?.runtimePlugins,
}), sharedLibraries.getReplacementPlugin());
// The env var is only set from the module-federation-dev-server
// Attach the runtime plugin
config.plugins.push(new core_1.DefinePlugin({
'process.env.NX_MF_DEV_REMOTES': process.env.NX_MF_DEV_REMOTES,
}));
return config;
};
}

View File

@@ -0,0 +1,11 @@
import { ModuleFederationConfig } from '../../utils';
/**
* Creates the default remote URL resolver for webpack.
* Kept for backward compatibility with existing configs.
*/
export declare function getFunctionDeterminateRemoteUrl(isServer?: boolean): (remote: string) => string;
export declare function getModuleFederationConfig(mfConfig: ModuleFederationConfig, options?: {
isServer: boolean;
determineRemoteUrl?: (remote: string) => string;
}, bundler?: 'rspack' | 'webpack'): Promise<import("../../utils/module-federation-config").ModuleFederationConfigResult>;
//# sourceMappingURL=utils.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../../packages/module-federation/src/with-module-federation/webpack/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAuB,MAAM,aAAa,CAAC;AAU1E;;;GAGG;AACH,wBAAgB,+BAA+B,CAAC,QAAQ,GAAE,OAAe,8BAExE;AAwBD,wBAAsB,yBAAyB,CAC7C,QAAQ,EAAE,sBAAsB,EAChC,OAAO,GAAE;IACP,QAAQ,EAAE,OAAO,CAAC;IAClB,kBAAkB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC;CAC3B,EACvB,OAAO,GAAE,QAAQ,GAAG,SAAoB,wFAOzC"}

View File

@@ -0,0 +1,32 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getFunctionDeterminateRemoteUrl = getFunctionDeterminateRemoteUrl;
exports.getModuleFederationConfig = getModuleFederationConfig;
const module_federation_config_1 = require("../../utils/module-federation-config");
const utils_1 = require("../react/utils");
const framework_detection_1 = require("../../utils/framework-detection");
/**
* Creates the default remote URL resolver for webpack.
* Kept for backward compatibility with existing configs.
*/
function getFunctionDeterminateRemoteUrl(isServer = false) {
return (0, module_federation_config_1.createDefaultRemoteUrlResolver)(isServer, 'js');
}
/**
* Framework config for webpack projects (React).
*/
function getWebpackFrameworkConfig(bundler = 'rspack') {
return {
bundler,
remoteEntryExt: 'js',
mapRemotesExpose: true,
applyEagerPackages: (sharedConfig, projectGraph, projectName) => {
if ((0, framework_detection_1.isReactProject)(projectName, projectGraph)) {
(0, utils_1.applyDefaultEagerPackages)(sharedConfig);
}
},
};
}
async function getModuleFederationConfig(mfConfig, options = { isServer: false }, bundler = 'rspack') {
return (0, module_federation_config_1.getModuleFederationConfigAsync)(mfConfig, options, getWebpackFrameworkConfig(bundler));
}

View File

@@ -0,0 +1,3 @@
import { ModuleFederationConfig, NxModuleFederationConfigOverride } from '../../utils';
export declare function withModuleFederationForSSR(options: ModuleFederationConfig, configOverride?: NxModuleFederationConfigOverride): Promise<(config: any) => any>;
//# sourceMappingURL=with-module-federation-ssr.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"with-module-federation-ssr.d.ts","sourceRoot":"","sources":["../../../../../../packages/module-federation/src/with-module-federation/webpack/with-module-federation-ssr.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EAEtB,gCAAgC,EACjC,MAAM,aAAa,CAAC;AAKrB,wBAAsB,0BAA0B,CAC9C,OAAO,EAAE,sBAAsB,EAC/B,cAAc,CAAC,EAAE,gCAAgC,iCAmFlD"}

View File

@@ -0,0 +1,68 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.withModuleFederationForSSR = withModuleFederationForSSR;
const utils_1 = require("../../utils");
const utils_2 = require("./utils");
const devkit_1 = require("@nx/devkit");
async function withModuleFederationForSSR(options, configOverride) {
if (global.NX_GRAPH_CREATION) {
return (config) => config;
}
const isDevServer = process.env['WEBPACK_SERVE'];
const { sharedLibraries, sharedDependencies, mappedRemotes } = await (0, utils_2.getModuleFederationConfig)(options, {
isServer: true,
}, 'webpack');
return (config) => {
config.target = 'async-node';
config.output.uniqueName = options.name;
config.resolve ??= {};
config.resolve.modules = [
...(config.resolve.modules ?? ['node_modules']),
devkit_1.workspaceRoot,
];
config.optimization = {
...(config.optimization ?? {}),
runtimeChunk: isDevServer
? (config.optimization?.runtimeChunk ?? undefined)
: false,
};
config.plugins.push(new (require('@module-federation/enhanced').ModuleFederationPlugin)({
name: (0, utils_1.normalizeProjectName)(options.name),
filename: 'remoteEntry.js',
exposes: options.exposes,
remotes: mappedRemotes,
shared: {
...sharedDependencies,
},
remoteType: 'script',
library: {
type: 'commonjs-module',
},
/**
* Apply user-defined config overrides
*/
...(configOverride ? configOverride : {}),
experiments: {
asyncStartup: true,
// We should allow users to override experiments
...(configOverride?.experiments ?? {}),
},
runtimePlugins: process.env.NX_MF_DEV_REMOTES &&
!options.disableNxRuntimeLibraryControlPlugin
? [
...(configOverride?.runtimePlugins ?? []),
require.resolve('@nx/module-federation/src/utils/plugins/runtime-library-control.plugin.js'),
]
: [
...(configOverride?.runtimePlugins ?? []),
require.resolve('@module-federation/node/runtimePlugin'),
],
}, {}), sharedLibraries.getReplacementPlugin());
// The env var is only set from the module-federation-dev-server
// Attach the runtime plugin
config.plugins.push(new (require('webpack').DefinePlugin)({
'process.env.NX_MF_DEV_REMOTES': process.env.NX_MF_DEV_REMOTES,
}));
return config;
};
}

View File

@@ -0,0 +1,6 @@
import { ModuleFederationConfig, NxModuleFederationConfigOverride } from '../../utils';
/**
* @param {ModuleFederationConfig} options
*/
export declare function withModuleFederation(options: ModuleFederationConfig, configOverride?: NxModuleFederationConfigOverride): Promise<(config: any, ctx: any) => any>;
//# sourceMappingURL=with-module-federation.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"with-module-federation.d.ts","sourceRoot":"","sources":["../../../../../../packages/module-federation/src/with-module-federation/webpack/with-module-federation.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EAEtB,gCAAgC,EACjC,MAAM,aAAa,CAAC;AAMrB;;GAEG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,sBAAsB,EAC/B,cAAc,CAAC,EAAE,gCAAgC,2CAgFlD"}

View File

@@ -0,0 +1,71 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.withModuleFederation = withModuleFederation;
const utils_1 = require("../../utils");
const utils_2 = require("./utils");
const webpack_1 = require("@module-federation/enhanced/webpack");
const devkit_1 = require("@nx/devkit");
/**
* @param {ModuleFederationConfig} options
*/
async function withModuleFederation(options, configOverride) {
if (global.NX_GRAPH_CREATION) {
return (config) => config;
}
const isDevServer = process.env['WEBPACK_SERVE'];
const { sharedDependencies, sharedLibraries, mappedRemotes } = await (0, utils_2.getModuleFederationConfig)(options, undefined, 'webpack');
return (config, ctx) => {
config.output.uniqueName = options.name;
config.output.publicPath = 'auto';
config.output.scriptType = 'text/javascript';
config.resolve ??= {};
config.resolve.modules = [
...(config.resolve.modules ?? ['node_modules']),
devkit_1.workspaceRoot,
];
config.optimization = {
...(config.optimization ?? {}),
runtimeChunk: isDevServer && !options.exposes
? (config.optimization?.runtimeChunk ?? undefined)
: false,
};
if (config.mode === 'development' &&
Object.keys(mappedRemotes).length > 1 &&
!options.exposes) {
config.optimization.runtimeChunk = 'single';
}
config.plugins.push(new webpack_1.ModuleFederationPlugin({
name: (0, utils_1.normalizeProjectName)(options.name),
filename: 'remoteEntry.js',
exposes: options.exposes,
remotes: mappedRemotes,
shared: {
...sharedDependencies,
},
/**
* remoteType: 'script' is required for the remote to be loaded as a script tag.
* remotes will need to be defined as:
* { appX: 'appX@http://localhost:3001/remoteEntry.js' }
* { appY: 'appY@http://localhost:3002/remoteEntry.js' }
*/
remoteType: 'script',
/**
* Apply user-defined config overrides
*/
...(configOverride ? configOverride : {}),
runtimePlugins: process.env.NX_MF_DEV_REMOTES &&
!options.disableNxRuntimeLibraryControlPlugin
? [
...(configOverride?.runtimePlugins ?? []),
require.resolve('@nx/module-federation/src/utils/plugins/runtime-library-control.plugin.js'),
]
: configOverride?.runtimePlugins,
}), sharedLibraries.getReplacementPlugin());
// The env var is only set from the module-federation-dev-server
// Attach the runtime plugin
config.plugins.push(new (require('webpack').DefinePlugin)({
'process.env.NX_MF_DEV_REMOTES': process.env.NX_MF_DEV_REMOTES,
}));
return config;
};
}