Skip to content

Commit

Permalink
feat(angular): support alternate remote entry filenames #10206 (#10432)
Browse files Browse the repository at this point in the history
  • Loading branch information
Coly010 committed May 24, 2022
1 parent e541a8a commit a299469
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
12 changes: 6 additions & 6 deletions packages/angular/src/utils/mfe/with-module-federation.ts
Expand Up @@ -18,6 +18,7 @@ import {
import { ParsedCommandLine } from 'typescript';
import { readWorkspaceJson } from 'nx/src/project-graph/file-utils';
import { readRootPackageJson } from './utils';
import { extname, join } from 'path';
import ModuleFederationPlugin = require('webpack/lib/container/ModuleFederationPlugin');

export type MFERemotes = string[] | [remoteName: string, remoteUrl: string][];
Expand Down Expand Up @@ -142,12 +143,11 @@ function mapRemotes(remotes: MFERemotes) {

for (const remote of remotes) {
if (Array.isArray(remote)) {
const remoteLocation = remote[1].match(/remoteEntry\.(js|mjs)/)
? remote[1]
: `${
remote[1].endsWith('/') ? remote[1].slice(0, -1) : remote[1]
}/remoteEntry.mjs`;
mappedRemotes[remote[0]] = remoteLocation;
const [remoteName, remoteLocation] = remote;
const remoteLocationExt = extname(remoteLocation);
mappedRemotes[remoteName] = ['.js', '.mjs'].includes(remoteLocationExt)
? remoteLocation
: join(remoteLocation, 'remoteEntry.mjs');
} else if (typeof remote === 'string') {
mappedRemotes[remote] = determineRemoteUrl(remote);
}
Expand Down
Expand Up @@ -44,12 +44,13 @@ export default async function* moduleFederationDevServer(
: [options.devRemotes];

for (const app of knownRemotes) {
const isDev = devServeApps.includes(app);
const [appName] = Array.isArray(app) ? app : [app];
const isDev = devServeApps.includes(appName);
iter = combineAsyncIterators(
iter,
await runExecutor(
{
project: app,
project: appName,
target: isDev ? 'serve' : 'serve-static',
configuration: context.configurationName,
},
Expand Down
15 changes: 6 additions & 9 deletions packages/react/src/module-federation/with-module-federation.ts
Expand Up @@ -23,8 +23,9 @@ import {
SharedFunction,
SharedLibraryConfig,
} from './models';
import ModuleFederationPlugin = require('webpack/lib/container/ModuleFederationPlugin');
import { readRootPackageJson } from './package-json';
import { extname, join } from 'path';
import ModuleFederationPlugin = require('webpack/lib/container/ModuleFederationPlugin');

function collectDependencies(
projectGraph: ProjectGraph,
Expand Down Expand Up @@ -131,14 +132,10 @@ function mapRemotes(remotes: Remotes) {
for (const remote of remotes) {
if (Array.isArray(remote)) {
let [remoteName, remoteLocation] = remote;
if (!remoteLocation.match(/remoteEntry\.(js|mjs)$/)) {
remoteLocation = `${
remoteLocation.endsWith('/')
? remoteLocation.slice(0, -1)
: remoteLocation
}/remoteEntry.js`;
}
mappedRemotes[remoteName] = remoteLocation;
const remoteLocationExt = extname(remoteLocation);
mappedRemotes[remoteName] = ['.js', '.mjs'].includes(remoteLocationExt)
? remoteLocation
: join(remoteLocation, 'remoteEntry.js');
} else if (typeof remote === 'string') {
mappedRemotes[remote] = determineRemoteUrl(remote);
}
Expand Down

0 comments on commit a299469

Please sign in to comment.