mirror of
https://github.com/angular/angular.git
synced 2026-11-23 07:05:14 -05:00
See associated pull request for more information. # Conflicts: # integration/animations/pnpm-lock.yaml # integration/cli-hello-world-ivy-i18n/pnpm-lock.yaml # integration/cli-hello-world-lazy/pnpm-lock.yaml # integration/cli-hello-world/pnpm-lock.yaml # integration/cli-signal-inputs/pnpm-lock.yaml # integration/defer/pnpm-lock.yaml # integration/legacy-animations-async/pnpm-lock.yaml # integration/legacy-animations/pnpm-lock.yaml # integration/ng-add-localize/pnpm-lock.yaml # integration/platform-server-hydration/pnpm-lock.yaml # integration/platform-server/pnpm-lock.yaml # integration/standalone-bootstrap/pnpm-lock.yaml # integration/trusted-types/pnpm-lock.yaml # pnpm-lock.yaml
46 lines
1.3 KiB
JavaScript
46 lines
1.3 KiB
JavaScript
/**
|
|
* @license
|
|
* Copyright Google LLC
|
|
*
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
* found in the LICENSE file at https://angular.dev/license
|
|
*/
|
|
|
|
/**
|
|
* Creates an ESBuild plugin that configures various Angular optimization.
|
|
* The optimization plugins usually run in the Angular CLI compilation pipeline.
|
|
*
|
|
* @param {import('./esbuild-plugin').OptimizationOptions} opts Options
|
|
*/
|
|
export function createEsbuildAngularOptimizePlugin(opts) {
|
|
return {
|
|
name: 'ng-optimize-esbuild',
|
|
setup: async (build) => {
|
|
const {JavaScriptTransformer} = (await import('@angular/build/private')).default;
|
|
const javascriptTransformer = new JavaScriptTransformer({
|
|
jit: false,
|
|
advancedOptimizations: !!opts.optimize,
|
|
sourcemap: !!build.initialOptions.sourcemap,
|
|
maxConcurrency: 2,
|
|
});
|
|
|
|
build.onLoad({filter: /\.[cm]?js$/}, async (args) => {
|
|
const contents = await javascriptTransformer.transformFile(args.path, {
|
|
skipLinker: !opts.enableLinker,
|
|
sideEffects: () => {
|
|
const sideEffects = opts.optimize?.isSideEffectFree?.(args.path) !== true;
|
|
|
|
return Promise.resolve(sideEffects);
|
|
},
|
|
});
|
|
|
|
return {contents};
|
|
});
|
|
|
|
build.onDispose(() => {
|
|
void javascriptTransformer.close();
|
|
});
|
|
},
|
|
};
|
|
}
|