Skip to content

Commit 266c829

Browse files
committed
Step 3 - Integrate all tasks into the build system; apply changes across the board.
1 parent 759b130 commit 266c829

File tree

5 files changed

+32
-16
lines changed

5 files changed

+32
-16
lines changed

apps/host-application/project.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@
4545
"budgets": [
4646
{
4747
"type": "initial",
48-
"maximumWarning": "500kb",
49-
"maximumError": "1mb"
48+
"maximumWarning": "5mb",
49+
"maximumError": "5mb"
5050
},
5151
{
5252
"type": "anyComponentStyle",
53-
"maximumWarning": "4kb",
54-
"maximumError": "8kb"
53+
"maximumWarning": "1mb",
54+
"maximumError": "8mb"
5555
}
5656
],
5757
"outputHashing": "all"

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

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { BuilderContext, createBuilder } from '@angular-devkit/architect';
22
import { buildApplication } from '@angular-devkit/build-angular';
3+
import { Plugin } from 'esbuild';
34

45
import { BuildExecutorSchema } from './schema';
5-
import { getMapName, prepareConfig } from '../helpers';
6+
import { getMapName, indexHtml, loadModule, prepareConfig } from '../helpers';
7+
import { entryPointForExtendDependencies, importMapConfigPlugin, serverSSRPlugin, moveCustomLoaderPlugin } from '../es-plugin';
68

79

810
export async function* runBuilder(
@@ -30,10 +32,26 @@ export async function* runBuilder(
3032
(i) => i.packageName
3133
);
3234

35+
const esPluginPromise = optionsMfe.esPlugins.map((item) =>
36+
loadModule<Plugin>(item, options.tsConfig, context.logger)
37+
);
38+
39+
const esPlugins = await Promise.all(esPluginPromise);
40+
const mainTransform = await indexHtml(optionsMfe);
41+
42+
const resultEsBuild = [
43+
...esPlugins,
44+
entryPointForExtendDependencies(optionsMfe),
45+
importMapConfigPlugin(optionsMfe),
46+
serverSSRPlugin(optionsMfe.deployUrl),
47+
moveCustomLoaderPlugin(),
48+
];
49+
3350
const extensions = {
34-
codePlugins: [],
35-
indexHtmlTransformer: (input) => {
36-
return input;
51+
codePlugins: resultEsBuild,
52+
indexHtmlTransformer: async (input) => {
53+
const mainTransformResult = await mainTransform(input);
54+
return optionsMfe.indexHtmlTransformer(mainTransformResult);
3755
},
3856
};
3957

libs/nx-angular-mf/src/builders/custom-loader/custom-loader.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
DeferredPromise,
66
resolveModulePath,
77
} from './custom-loader-utils';
8-
import { getResultImportMap } from '../helpers';
8+
import { getResultImportMap, IMPORT_MAP_CONFIG_NAME } from '../helpers/init-import-map-utils';
99
import { pathToFileURL } from 'url';
1010
// @ts-expect-error should be esm
1111
import type { ImportMap } from '@jspm/import-map';
@@ -21,12 +21,12 @@ const fakeRootPath = pathToFileURL(
2121
).toString();
2222

2323
async function initImportMap(deployHost: string) {
24-
const deployUrl = new URL('importmap.json', deployHost);
24+
const deployUrl = new URL(IMPORT_MAP_CONFIG_NAME, deployHost);
2525
const importMapConfig = await fetch(deployUrl)
2626
.then((r) => r.json())
2727
.catch((err) => {
2828
const newError = new Error(
29-
`Fetch "importmap.json" from "${deployHost}" failed`,
29+
`Fetch "${IMPORT_MAP_CONFIG_NAME}" from "${deployHost}" failed`,
3030
{ cause: err }
3131
);
3232
throw newError;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
export * from './entry-point-for-extend-dependencies'
22
export * from './import-map-config'
3+
export * from './server-ssr-plugin'
4+
export * from './move-custom-loader-plugin'

libs/nx-angular-mf/src/builders/es-plugin/move-custom-loader-plugin.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,14 @@ export function moveCustomLoaderPlugin(): Plugin {
1414
...build.initialOptions.entryPoints,
1515
[customLoaderName]: customLoaderName,
1616
};
17-
build.initialOptions.external = [
18-
...build.initialOptions.external,
19-
'./server.mjs',
20-
];
2117
build.onResolve(
2218
{ filter: new RegExp('^' + customLoaderName) },
2319
({ kind, path }) => {
24-
console.log(kind, path);
2520
if (kind === 'import-statement') {
2621
return {
2722
path: join(pathToCustomLoaderFolder, 'custom-loader.js'),
2823
};
24+
2925
}
3026
return {
3127
path: path,

0 commit comments

Comments
 (0)