Skip to content

Commit c8bee84

Browse files
clydinalan-agius4
authored andcommitted
fix(@angular/build): allow .js file replacements in all configuration cases
Previously the `fileReplacements` option within the `application` builder would only replace `.js` files if the TypeScript `allowJs` option was enabled. This differs from the `browser` builder which did not require the option. To minimize friction when migrating to the new build system, the `allowJs` option is no longer required for this file replacement case. (cherry picked from commit a325c9a)
1 parent f58e689 commit c8bee84

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

packages/angular/build/src/tools/esbuild/angular/compiler-plugin.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -431,19 +431,28 @@ export function createCompilerPlugin(
431431
build.onLoad(
432432
{ filter: /\.[cm]?js$/ },
433433
createCachedLoad(pluginOptions.loadResultCache, async (args) => {
434+
let request = args.path;
435+
if (pluginOptions.fileReplacements) {
436+
const replacement = pluginOptions.fileReplacements[path.normalize(args.path)];
437+
if (replacement) {
438+
request = path.normalize(replacement);
439+
}
440+
}
441+
434442
return profileAsync(
435443
'NG_EMIT_JS*',
436444
async () => {
437-
const sideEffects = await hasSideEffects(args.path);
445+
const sideEffects = await hasSideEffects(request);
438446
const contents = await javascriptTransformer.transformFile(
439-
args.path,
447+
request,
440448
pluginOptions.jit,
441449
sideEffects,
442450
);
443451

444452
return {
445453
contents,
446454
loader: 'js',
455+
watchFiles: request !== args.path ? [request] : undefined,
447456
};
448457
},
449458
true,

0 commit comments

Comments
 (0)