fix(@angular-devkit/build-angular): use browserslist when processing global scripts in application builder

When using the `scripts` option with the esbuild-based builders (`application`/`browser-esbuild`), the
JavaScript code from the scripts will now be processed based on the targets provided in the application's
browserslist file. This prevents unsupported syntax from being present in the output script chunk that is
generated.
This commit is contained in:
Charles Lyding 2023-10-31 16:04:38 -04:00 committed by Alan Agius
parent bb74a21114
commit 2aa55ec096
2 changed files with 3 additions and 1 deletions

View File

@ -108,7 +108,7 @@ export async function executeBuild(
// Global Scripts
if (options.globalScripts.length > 0) {
for (const initial of [true, false]) {
const bundleOptions = createGlobalScriptsBundleOptions(options, initial);
const bundleOptions = createGlobalScriptsBundleOptions(options, target, initial);
if (bundleOptions) {
bundlerContexts.push(
new BundlerContext(workspaceRoot, !!options.watch, bundleOptions, () => initial),

View File

@ -25,6 +25,7 @@ import { createVirtualModulePlugin } from './virtual-module-plugin';
*/
export function createGlobalScriptsBundleOptions(
options: NormalizedApplicationBuildOptions,
target: string[],
initial: boolean,
): BundlerOptionsFactory | undefined {
const {
@ -69,6 +70,7 @@ export function createGlobalScriptsBundleOptions(
sourcemap: sourcemapOptions.scripts && (sourcemapOptions.hidden ? 'external' : true),
write: false,
platform: 'neutral',
target,
preserveSymlinks,
plugins: [
createSourcemapIgnorelistPlugin(),