Skip to content

Commit 8464b64

Browse files
leosvelperezFrozenPandaz
authored andcommitted
fix(angular): resolve the index html transformer correctly for esbuild based build targets in dev-server (#21679)
(cherry picked from commit db4c617)
1 parent 280056c commit 8464b64

File tree

1 file changed

+81
-51
lines changed

1 file changed

+81
-51
lines changed

packages/angular/src/builders/dev-server/dev-server.impl.ts

Lines changed: 81 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { combineLatest, from } from 'rxjs';
2424
import { switchMap } from 'rxjs/operators';
2525
import { getInstalledAngularVersionInfo } from '../../executors/utilities/angular-version-utils';
2626
import {
27+
loadIndexHtmlTransformer,
2728
loadMiddleware,
2829
loadPlugins,
2930
type PluginSpec,
@@ -182,62 +183,72 @@ export function executeDevServerBuilder(
182183
from(
183184
loadMiddleware(options.esbuildMiddleware, buildTargetOptions.tsConfig)
184185
),
185-
]).pipe(
186-
switchMap(([{ executeDevServerBuilder }, plugins, middleware]) =>
187-
executeDevServerBuilder(
188-
delegateBuilderOptions,
186+
from(
187+
loadIndexHtmlFileTransformer(
188+
pathToIndexFileTransformer,
189+
buildTargetOptions.tsConfig,
189190
context,
190-
{
191-
webpackConfiguration: isUsingWebpackBuilder
192-
? async (baseWebpackConfig) => {
193-
if (!buildLibsFromSource) {
194-
const workspaceDependencies = dependencies
195-
.filter((dep) => !isNpmProject(dep.node))
196-
.map((dep) => dep.node.name);
197-
// default for `nx run-many` is --all projects
198-
// by passing an empty string for --projects, run-many will default to
199-
// run the target for all projects.
200-
// This will occur when workspaceDependencies = []
201-
if (workspaceDependencies.length > 0) {
202-
baseWebpackConfig.plugins.push(
203-
// @ts-expect-error - difference between angular and webpack plugin definitions bc of webpack versions
204-
new WebpackNxBuildCoordinationPlugin(
205-
`nx run-many --target=${
206-
parsedBuildTarget.target
207-
} --projects=${workspaceDependencies.join(',')}`
208-
)
209-
);
191+
isUsingWebpackBuilder
192+
)
193+
),
194+
]).pipe(
195+
switchMap(
196+
([
197+
{ executeDevServerBuilder },
198+
plugins,
199+
middleware,
200+
indexHtmlTransformer,
201+
]) =>
202+
executeDevServerBuilder(
203+
delegateBuilderOptions,
204+
context,
205+
{
206+
webpackConfiguration: isUsingWebpackBuilder
207+
? async (baseWebpackConfig) => {
208+
if (!buildLibsFromSource) {
209+
const workspaceDependencies = dependencies
210+
.filter((dep) => !isNpmProject(dep.node))
211+
.map((dep) => dep.node.name);
212+
// default for `nx run-many` is --all projects
213+
// by passing an empty string for --projects, run-many will default to
214+
// run the target for all projects.
215+
// This will occur when workspaceDependencies = []
216+
if (workspaceDependencies.length > 0) {
217+
baseWebpackConfig.plugins.push(
218+
// @ts-expect-error - difference between angular and webpack plugin definitions bc of webpack versions
219+
new WebpackNxBuildCoordinationPlugin(
220+
`nx run-many --target=${
221+
parsedBuildTarget.target
222+
} --projects=${workspaceDependencies.join(',')}`
223+
)
224+
);
225+
}
226+
}
227+
228+
if (!pathToWebpackConfig) {
229+
return baseWebpackConfig;
210230
}
211-
}
212231

213-
if (!pathToWebpackConfig) {
214-
return baseWebpackConfig;
232+
return mergeCustomWebpackConfig(
233+
baseWebpackConfig,
234+
pathToWebpackConfig,
235+
buildTargetOptions,
236+
context.target
237+
);
215238
}
239+
: undefined,
216240

217-
return mergeCustomWebpackConfig(
218-
baseWebpackConfig,
219-
pathToWebpackConfig,
220-
buildTargetOptions,
221-
context.target
222-
);
223-
}
224-
: undefined,
225-
226-
...(pathToIndexFileTransformer
227-
? {
228-
indexHtml: resolveIndexHtmlTransformer(
229-
pathToIndexFileTransformer,
230-
buildTargetOptions.tsConfig,
231-
context.target
232-
),
233-
}
234-
: {}),
235-
},
236-
{
237-
buildPlugins: plugins,
238-
middleware,
239-
}
240-
)
241+
...(indexHtmlTransformer
242+
? {
243+
indexHtml: indexHtmlTransformer,
244+
}
245+
: {}),
246+
},
247+
{
248+
buildPlugins: plugins,
249+
middleware,
250+
}
251+
)
241252
)
242253
);
243254
}
@@ -267,6 +278,25 @@ function getDelegateBuilderOptions(
267278
return delegateBuilderOptions;
268279
}
269280

281+
async function loadIndexHtmlFileTransformer(
282+
pathToIndexFileTransformer: string | undefined,
283+
tsConfig: string,
284+
context: BuilderContext,
285+
isUsingWebpackBuilder: boolean
286+
) {
287+
if (!pathToIndexFileTransformer) {
288+
return undefined;
289+
}
290+
291+
return isUsingWebpackBuilder
292+
? resolveIndexHtmlTransformer(
293+
pathToIndexFileTransformer,
294+
tsConfig,
295+
context.target
296+
)
297+
: await loadIndexHtmlTransformer(pathToIndexFileTransformer, tsConfig);
298+
}
299+
270300
const executorToBuilderMap = new Map<string, string>([
271301
[
272302
'@nx/angular:browser-esbuild',

0 commit comments

Comments
 (0)