Skip to content

Commit e1b7aa9

Browse files
committed
Step 2 - Enhance esbuild with plugin to handle dependencies; add new entryPoints based on dependency list.
1 parent 05374b2 commit e1b7aa9

File tree

6 files changed

+75
-6
lines changed

6 files changed

+75
-6
lines changed

apps/host-application/tsconfig.app.json

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,22 @@
22
"extends": "./tsconfig.json",
33
"compilerOptions": {
44
"outDir": "../../dist/out-tsc",
5-
"types": ["node"]
5+
"types": [
6+
"node"
7+
]
68
},
7-
"files": ["src/main.ts", "src/main.server.ts", "src/server.ts"],
8-
"include": ["src/**/*.d.ts"],
9-
"exclude": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts"]
9+
"files": [
10+
"src/main.ts",
11+
"src/main.server.ts",
12+
"src/server.ts",
13+
"../../libs/test-shared-library/src/index.ts"
14+
],
15+
"include": [
16+
"src/**/*.d.ts"
17+
],
18+
"exclude": [
19+
"jest.config.ts",
20+
"src/**/*.test.ts",
21+
"src/**/*.spec.ts"
22+
]
1023
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { Plugin, PluginBuild } from 'esbuild';
2+
3+
import { ConfigMf } from '../types';
4+
import { getMapName } from '../helpers';
5+
6+
7+
export function entryPointForExtendDependencies(config: ConfigMf): Plugin {
8+
return {
9+
name: 'entryPointForExtendDependencies',
10+
setup(build: PluginBuild) {
11+
const mapShareObject = getMapName(config.shared, config.sharedMappings);
12+
13+
const result = [...mapShareObject.entries()].reduce(
14+
(acum, [key, value]) => {
15+
acum[key] = value.entryPoint;
16+
return acum;
17+
},
18+
{ }
19+
);
20+
21+
delete build.initialOptions.define.ngServerMode;
22+
build.initialOptions.splitting = false;
23+
24+
if (build.initialOptions.platform !== 'browser') return;
25+
26+
build.onEnd((resultBuild) => {
27+
if (!resultBuild.metafile) return;
28+
config.outPutFileNames = Object.keys(
29+
resultBuild.metafile.outputs
30+
).filter((r) => !r.endsWith('.map'));
31+
});
32+
build.initialOptions.entryPoints = {
33+
...build.initialOptions.entryPoints,
34+
...result,
35+
};
36+
},
37+
};
38+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './entry-point-for-extend-dependencies'

libs/nx-angular-mf/src/builders/helpers/prepare-config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export async function prepareConfig(
3434
sharedMappings: getSharedMappings().filter(
3535
(i) => !skipList.includes(i.key)
3636
),
37+
outPutFileNames: []
3738
};
3839
}
3940

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,21 @@ import {
1212
import { ServeExecutorSchema } from './schema';
1313
import { BuildExecutorSchema } from '../build/schema';
1414
import { deepMergeObject, getMapName, patchBuilderContext, prepareConfig } from '../helpers';
15+
import { entryPointForExtendDependencies } from '../es-plugin';
1516

1617

1718
function getBuilderAction() {
18-
return async function* (options, context, extensions) {
19+
return async function* (options, context, pluginsOrExtensions) {
20+
21+
let extensions;
22+
if (pluginsOrExtensions && Array.isArray(pluginsOrExtensions)) {
23+
extensions = {
24+
codePlugins: pluginsOrExtensions,
25+
};
26+
} else {
27+
extensions = pluginsOrExtensions;
28+
}
29+
1930
for await (const result of buildApplicationInternal(
2031
options,
2132
context,
@@ -67,9 +78,13 @@ export async function* runBuilder(
6778
defaultOptions
6879
);
6980

81+
const resultEsBuild = [
82+
entryPointForExtendDependencies(optionsMfe)
83+
]
84+
7085
const extensions = {
7186
middleware: [],
72-
buildPlugins: [],
87+
buildPlugins: resultEsBuild,
7388
};
7489

7590
const transforms = {

libs/nx-angular-mf/src/builders/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export type ConfigMf = {
33
externalList: string[];
44
shared: SharedMap;
55
sharedMappings: { key: string; path: string }[];
6+
outPutFileNames: string[];
67
};
78

89
export type ShareOptions = {

0 commit comments

Comments
 (0)