Skip to content

Commit

Permalink
feat(react): Treat window and var library types the same (#20597)
Browse files Browse the repository at this point in the history
  • Loading branch information
ashwinGokhale authored Dec 12, 2023
1 parent 8caebc5 commit d9540ef
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/react/src/module-federation/with-module-federation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { getModuleFederationConfig } from './utils';
import type { AsyncNxComposableWebpackPlugin } from '@nx/webpack';
import ModuleFederationPlugin = require('webpack/lib/container/ModuleFederationPlugin');

const isVarOrWindow = (libType?: string) =>
libType === 'var' || libType === 'window';

/**
* @param {ModuleFederationConfig} options
* @return {Promise<AsyncNxComposableWebpackPlugin>}
Expand All @@ -12,12 +15,13 @@ export async function withModuleFederation(
): Promise<AsyncNxComposableWebpackPlugin> {
const { sharedDependencies, sharedLibraries, mappedRemotes } =
await getModuleFederationConfig(options);
const isGlobal = isVarOrWindow(options.library?.type);

return (config, ctx) => {
config.output.uniqueName = options.name;
config.output.publicPath = 'auto';

if (options.library?.type === 'var') {
if (isGlobal) {
config.output.scriptType = 'text/javascript';
}

Expand All @@ -27,7 +31,7 @@ export async function withModuleFederation(

config.experiments = {
...config.experiments,
outputModule: !(options.library?.type === 'var'),
outputModule: !isGlobal,
};

config.plugins.push(
Expand All @@ -46,7 +50,7 @@ export async function withModuleFederation(
* { appX: 'appX@http://localhost:3001/remoteEntry.js' }
* { appY: 'appY@http://localhost:3002/remoteEntry.js' }
*/
...(options.library?.type === 'var' ? { remoteType: 'script' } : {}),
...(isGlobal ? { remoteType: 'script' } : {}),
}),
sharedLibraries.getReplacementPlugin()
);
Expand Down

0 comments on commit d9540ef

Please sign in to comment.