Skip to content

Commit

Permalink
fix(angular): dynamic host should not generate webpack.prod.config.js (
Browse files Browse the repository at this point in the history
  • Loading branch information
Coly010 committed Jun 2, 2023
1 parent 6c84353 commit a775325
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
@@ -1,18 +1,35 @@
import type { Tree } from '@nx/devkit';
import { joinPathFragments, readProjectConfiguration } from '@nx/devkit';
import {
joinPathFragments,
readProjectConfiguration,
updateProjectConfiguration,
} from '@nx/devkit';
import type { Schema } from '../schema';

export function setupHostIfDynamic(tree: Tree, options: Schema) {
if (options.federationType === 'static') {
return;
}

const project = readProjectConfiguration(tree, options.appName);
const pathToMFManifest = joinPathFragments(
readProjectConfiguration(tree, options.appName).sourceRoot,
project.sourceRoot,
'assets/module-federation.manifest.json'
);

if (!tree.exists(pathToMFManifest)) {
tree.write(pathToMFManifest, '{}');
}

const pathToProdWebpackConfig = joinPathFragments(
project.root,
'webpack.prod.config.js'
);
if (tree.exists(pathToProdWebpackConfig)) {
tree.delete(pathToProdWebpackConfig);
}

delete project.targets.build.configurations.production?.customWebpackConfig;

updateProjectConfiguration(tree, options.appName, project);
}
14 changes: 14 additions & 0 deletions packages/angular/src/generators/setup-mf/setup-mf.spec.ts
Expand Up @@ -135,6 +135,20 @@ describe('Init MF', () => {
}
);

it('should not generate a webpack prod file for dynamic host', async () => {
// ACT
await setupMf(tree, {
appName: 'app1',
mfType: 'host',
federationType: 'dynamic',
});

// ASSERT
const { build } = readProjectConfiguration(tree, 'app1').targets;
expect(tree.exists('apps/app1/webpack.prod.config.js')).toBeFalsy();
expect(build.configurations.production.customWebpackConfig).toBeUndefined();
});

it('should generate the remote entry module and component correctly', async () => {
// ACT
await setupMf(tree, {
Expand Down
10 changes: 5 additions & 5 deletions packages/angular/src/generators/setup-mf/setup-mf.ts
Expand Up @@ -36,11 +36,6 @@ export async function setupMf(tree: Tree, rawOptions: Schema) {
const options = normalizeOptions(tree, rawOptions);
const projectConfig = readProjectConfiguration(tree, options.appName);

if (options.mfType === 'host') {
setupHostIfDynamic(tree, options);
updateHostAppRoutes(tree, options);
}

let installTask = () => {};
if (options.mfType === 'remote') {
addRemoteToHost(tree, options);
Expand All @@ -63,6 +58,11 @@ export async function setupMf(tree: Tree, rawOptions: Schema) {

fixBootstrap(tree, projectConfig.root, options);

if (options.mfType === 'host') {
setupHostIfDynamic(tree, options);
updateHostAppRoutes(tree, options);
}

if (!options.skipE2E) {
addCypressOnErrorWorkaround(tree, options);
}
Expand Down

1 comment on commit a775325

@vercel
Copy link

@vercel vercel bot commented on a775325 Jun 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-git-master-nrwl.vercel.app
nx-dev-nrwl.vercel.app
nx-five.vercel.app
nx.dev

Please sign in to comment.