Skip to content

Commit 7159a03

Browse files
Coly010FrozenPandaz
authored andcommitted
fix(angular): dynamic host should not generate webpack.prod.config.js (#17385)
(cherry picked from commit a775325)
1 parent 940a8d7 commit 7159a03

3 files changed

Lines changed: 38 additions & 7 deletions

File tree

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,35 @@
11
import type { Tree } from '@nx/devkit';
2-
import { joinPathFragments, readProjectConfiguration } from '@nx/devkit';
2+
import {
3+
joinPathFragments,
4+
readProjectConfiguration,
5+
updateProjectConfiguration,
6+
} from '@nx/devkit';
37
import type { Schema } from '../schema';
48

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

14+
const project = readProjectConfiguration(tree, options.appName);
1015
const pathToMFManifest = joinPathFragments(
11-
readProjectConfiguration(tree, options.appName).sourceRoot,
16+
project.sourceRoot,
1217
'assets/module-federation.manifest.json'
1318
);
1419

1520
if (!tree.exists(pathToMFManifest)) {
1621
tree.write(pathToMFManifest, '{}');
1722
}
23+
24+
const pathToProdWebpackConfig = joinPathFragments(
25+
project.root,
26+
'webpack.prod.config.js'
27+
);
28+
if (tree.exists(pathToProdWebpackConfig)) {
29+
tree.delete(pathToProdWebpackConfig);
30+
}
31+
32+
delete project.targets.build.configurations.production?.customWebpackConfig;
33+
34+
updateProjectConfiguration(tree, options.appName, project);
1835
}

packages/angular/src/generators/setup-mf/setup-mf.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,20 @@ describe('Init MF', () => {
135135
}
136136
);
137137

138+
it('should not generate a webpack prod file for dynamic host', async () => {
139+
// ACT
140+
await setupMf(tree, {
141+
appName: 'app1',
142+
mfType: 'host',
143+
federationType: 'dynamic',
144+
});
145+
146+
// ASSERT
147+
const { build } = readProjectConfiguration(tree, 'app1').targets;
148+
expect(tree.exists('apps/app1/webpack.prod.config.js')).toBeFalsy();
149+
expect(build.configurations.production.customWebpackConfig).toBeUndefined();
150+
});
151+
138152
it('should generate the remote entry module and component correctly', async () => {
139153
// ACT
140154
await setupMf(tree, {

packages/angular/src/generators/setup-mf/setup-mf.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@ export async function setupMf(tree: Tree, rawOptions: Schema) {
3636
const options = normalizeOptions(tree, rawOptions);
3737
const projectConfig = readProjectConfiguration(tree, options.appName);
3838

39-
if (options.mfType === 'host') {
40-
setupHostIfDynamic(tree, options);
41-
updateHostAppRoutes(tree, options);
42-
}
43-
4439
let installTask = () => {};
4540
if (options.mfType === 'remote') {
4641
addRemoteToHost(tree, options);
@@ -63,6 +58,11 @@ export async function setupMf(tree: Tree, rawOptions: Schema) {
6358

6459
fixBootstrap(tree, projectConfig.root, options);
6560

61+
if (options.mfType === 'host') {
62+
setupHostIfDynamic(tree, options);
63+
updateHostAppRoutes(tree, options);
64+
}
65+
6666
if (!options.skipE2E) {
6767
addCypressOnErrorWorkaround(tree, options);
6868
}

0 commit comments

Comments
 (0)