Skip to content

Commit 1af0fb1

Browse files
Merged 'main' into 'release'.
2 parents a092c62 + 35f4bc9 commit 1af0fb1

File tree

4 files changed

+38
-15
lines changed

4 files changed

+38
-15
lines changed

libs/nx-angular-mf/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Here’s an example of how the configuration might look in practice:
8282
{
8383
"skipList": ["dependency-to-skip"] // or 'dependency-to-skip.json',
8484
"externalList": ["@angular/core", "@angular/platform-browser"], // or 'external-list-dependency.json',
85-
"esPlugins": ["path/to/esbuild/plugin1.ts", "path/to/esbuild/plugin2.ts"],
85+
"esPlugins": ["path/to/esbuild/plugin1.ts", "path/to/esbuild/plugin2.ts"], // should be export default Plugin or () => Promise<Plugin>
8686
"indexHtmlTransformer": "path/to/transform-index.ts",
8787
"exposes": {
8888
"./ComponentA": "./src/component-a.ts"
@@ -94,6 +94,9 @@ Here’s an example of how the configuration might look in practice:
9494
}
9595

9696
```
97+
- Module with `esPlugins` should be export `Plugin` as default of `(configMf: ConfigMf) => Promise<Plugin>` as default too.
98+
- Module with `indexHtmlTransformer` should be export `(input: string) => string` as default
99+
97100
This configuration excludes a dependency from processing, treats Angular core modules as external, includes custom plugins, modifies index.html, exposes a component, specifies a remote entry, and supports deployment via an environment variable.
98101

99102
### Import dinamic remote module

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export async function resolve(
113113
const resolveUrl = resolveModulePath(importMap, specifier, parentURL);
114114

115115
if (checkIfNodeProtocol(resolveUrl) || checkIfFileProtocol(resolveUrl)) {
116-
return nextResolve(specifier, context, nextResolve);
116+
return nextResolve(specifier.replace('@fs/', ''), context, nextResolve);
117117
}
118118

119119
if (!importMapName && !resolveUrl) {

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

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,20 @@ import {
2020
indexHtml,
2121
loadModule,
2222
patchBuilderContext,
23-
prepareConfig, reloadDevServer
23+
prepareConfig,
24+
reloadDevServer,
2425
} from '../helpers';
25-
import { entryPointForExtendDependencies, importMapConfigPlugin } from '../es-plugin';
26+
import {
27+
entryPointForExtendDependencies,
28+
importMapConfigPlugin,
29+
} from '../es-plugin';
2630
import { register } from 'node:module';
27-
import { CACHE_FILE, CLEAR_REMOTE, IMPORT_MAP } from '../custom-loader/constants';
28-
import { OutputFileRecord } from '../types';
31+
import {
32+
CACHE_FILE,
33+
CLEAR_REMOTE,
34+
IMPORT_MAP,
35+
} from '../custom-loader/constants';
36+
import { ConfigMf, OutputFileRecord } from '../types';
2937
import process from 'node:process';
3038
import { loadEsmModule } from '../custom-loader/custom-loader-utils';
3139
// @ts-expect-error need only type
@@ -40,7 +48,6 @@ function getBuilderAction(
4048
ssr: boolean
4149
) {
4250
return async function* (options, context, pluginsOrExtensions) {
43-
4451
let extensions;
4552
if (pluginsOrExtensions && Array.isArray(pluginsOrExtensions)) {
4653
extensions = {
@@ -104,7 +111,7 @@ export async function* runBuilder(
104111
) {
105112
context.logger.info('Run serve mf');
106113

107-
const {mf: defaultOptionsMfe, ...defaultOptions} = options;
114+
const { mf: defaultOptionsMfe, ...defaultOptions } = options;
108115

109116
const buildTarget = targetFromTargetString(options.buildTarget);
110117
const targetOptions = (await context.getTargetOptions(
@@ -147,16 +154,27 @@ export async function* runBuilder(
147154
defaultOptions
148155
);
149156

150-
const esPluginPromise = optionsMfe.esPlugins.map((item) =>
151-
loadModule<Plugin>(item, targetOptions.tsConfig, context.logger)
152-
);
157+
type FunctionEsPlugin = (config: ConfigMf) => Promise<Plugin>;
158+
159+
const esPluginPromise = optionsMfe.esPlugins.map((item) => {
160+
return loadModule<Plugin | FunctionEsPlugin>(
161+
item,
162+
targetOptions.tsConfig,
163+
context.logger
164+
).then(r => {
165+
if (typeof r === 'function') {
166+
return r(optionsMfe)
167+
}
168+
return r;
169+
});
170+
});
153171
const esPlugins = await Promise.all(esPluginPromise);
154172

155173
const resultEsBuild = [
156174
...esPlugins,
157175
importMapConfigPlugin(optionsMfe, true),
158-
entryPointForExtendDependencies(optionsMfe)
159-
]
176+
entryPointForExtendDependencies(optionsMfe),
177+
];
160178

161179
const extensions = {
162180
middleware: [],
@@ -165,10 +183,11 @@ export async function* runBuilder(
165183

166184
const mainTransform = await indexHtml(optionsMfe, true);
167185

168-
169186
const transforms = {
170187
indexHtml: async (input: string) => {
171-
const mainTransformResult = await mainTransform(addLinkForReload(input));
188+
const mainTransformResult = await mainTransform(
189+
targetOptions['ssr'] ? addLinkForReload(input) : input
190+
);
172191
return optionsMfe.indexHtmlTransformer(mainTransformResult);
173192
},
174193
};

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './builders/types'

0 commit comments

Comments
 (0)