Skip to content

Commit 1e029ef

Browse files
committed
fix(nx-angular-mf): extract Angular SSR path resolver plugin
Moved Angular SSR path resolution logic to a dedicated plugin for better modularity and maintainability. Integrated the new plugin into the builder and cleaned up duplicate code from existing plugins.
1 parent ae8c479 commit 1e029ef

File tree

4 files changed

+32
-16
lines changed

4 files changed

+32
-16
lines changed

libs/nx-angular-mf/src/builders/build/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@ import { Plugin } from 'esbuild';
44

55
import { BuildExecutorSchema } from './schema';
66
import { getMapName, indexHtml, loadModule, prepareConfig } from '../helpers';
7-
import { entryPointForExtendDependencies, importMapConfigPlugin, serverSSRPlugin, moveCustomLoaderPlugin } from '../es-plugin';
8-
7+
import {
8+
entryPointForExtendDependencies,
9+
importMapConfigPlugin,
10+
serverSSRPlugin,
11+
moveCustomLoaderPlugin,
12+
changePathForAngularSsrNode,
13+
} from '../es-plugin';
914

1015
export async function* runBuilder(
1116
options: BuildExecutorSchema,
@@ -45,6 +50,7 @@ export async function* runBuilder(
4550
importMapConfigPlugin(optionsMfe),
4651
serverSSRPlugin(optionsMfe.deployUrl),
4752
moveCustomLoaderPlugin(),
53+
changePathForAngularSsrNode(),
4854
];
4955
// @ts-ignore
5056
defaultOptions.partialSSRBuild = true;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { Plugin, PluginBuild } from 'esbuild';
2+
3+
4+
export function changePathForAngularSsrNode(): Plugin {
5+
return {
6+
name: 'log-plugin',
7+
setup(build: PluginBuild) {
8+
if (build.initialOptions.entryPoints['server']) {
9+
build.onResolve({ filter: /./ }, (data) => {
10+
const { path } = data;
11+
if (path === '@angular/ssr/node') {
12+
return {
13+
path: require.resolve('@angular/ssr/node', {
14+
paths: [process.cwd()],
15+
}),
16+
};
17+
}
18+
return null;
19+
});
20+
}
21+
},
22+
}
23+
}

libs/nx-angular-mf/src/builders/es-plugin/entry-point-for-extend-dependencies.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,6 @@ export function entryPointForExtendDependencies(config: ConfigMf): Plugin {
2121
delete build.initialOptions.define.ngServerMode;
2222
build.initialOptions.splitting = false;
2323

24-
if (build.initialOptions.entryPoints['server']) {
25-
build.onResolve({ filter: /./ }, (data) => {
26-
const { path } = data;
27-
if (path === '@angular/ssr/node') {
28-
return {
29-
path: require.resolve('@angular/ssr/node', {
30-
paths: [process.cwd()],
31-
}),
32-
};
33-
}
34-
return null;
35-
});
36-
}
37-
3824
if (build.initialOptions.platform !== 'browser') return;
3925

4026
build.onEnd((resultBuild) => {

libs/nx-angular-mf/src/builders/es-plugin/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export * from './entry-point-for-extend-dependencies'
22
export * from './import-map-config'
33
export * from './server-ssr-plugin'
44
export * from './move-custom-loader-plugin'
5+
export * from './change-path-for-angular-ssr-node'

0 commit comments

Comments
 (0)