Skip to content

Commit

Permalink
fix(@angular/build): allow .js file replacements in all configuration…
Browse files Browse the repository at this point in the history
… 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)
  • Loading branch information
clydin authored and alan-agius4 committed Nov 8, 2024
1 parent f58e689 commit c8bee84
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -431,19 +431,28 @@ export function createCompilerPlugin(
build.onLoad(
{ filter: /\.[cm]?js$/ },
createCachedLoad(pluginOptions.loadResultCache, async (args) => {
let request = args.path;
if (pluginOptions.fileReplacements) {
const replacement = pluginOptions.fileReplacements[path.normalize(args.path)];
if (replacement) {
request = path.normalize(replacement);
}
}

return profileAsync(
'NG_EMIT_JS*',
async () => {
const sideEffects = await hasSideEffects(args.path);
const sideEffects = await hasSideEffects(request);
const contents = await javascriptTransformer.transformFile(
args.path,
request,
pluginOptions.jit,
sideEffects,
);

return {
contents,
loader: 'js',
watchFiles: request !== args.path ? [request] : undefined,
};
},
true,
Expand Down

0 comments on commit c8bee84

Please sign in to comment.