Skip to content

Commit 53b6cd3

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 a39825e commit 53b6cd3

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
@@ -483,19 +483,28 @@ export function createCompilerPlugin(
483483
build.onLoad(
484484
{ filter: /\.[cm]?js$/ },
485485
createCachedLoad(pluginOptions.loadResultCache, async (args) => {
486+
let request = args.path;
487+
if (pluginOptions.fileReplacements) {
488+
const replacement = pluginOptions.fileReplacements[path.normalize(args.path)];
489+
if (replacement) {
490+
request = path.normalize(replacement);
491+
}
492+
}
493+
486494
return profileAsync(
487495
'NG_EMIT_JS*',
488496
async () => {
489-
const sideEffects = await hasSideEffects(args.path);
497+
const sideEffects = await hasSideEffects(request);
490498
const contents = await javascriptTransformer.transformFile(
491-
args.path,
499+
request,
492500
pluginOptions.jit,
493501
sideEffects,
494502
);
495503

496504
return {
497505
contents,
498506
loader: 'js',
507+
watchFiles: request !== args.path ? [request] : undefined,
499508
};
500509
},
501510
true,

0 commit comments

Comments
 (0)