/
githubmirror
/
angular-cli
Обзор
Документация
Войти
/
githubmirror
/
angular-cli
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/angular/build/src/builders/application/setup-bundling.ts
220 строк
7 KB
Alan Agius
fix(@angular/build): return only lowest version per target engine
07 авг 2026, 16:28
07 авг 2026, 16:28
3c7ac15
Код
Авторство
О чём код?
/** * @license * Copyright Google LLC All Rights Reserved. * * 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 */ import type { AngularCompilationContext } from '../../tools/esbuild/angular/compilation-state'; import { ComponentStylesheetBundler } from '../../tools/esbuild/angular/component-stylesheets'; import type { SourceFileCache } from '../../tools/esbuild/angular/source-file-cache'; import { createBrowserCodeBundleOptions, createBrowserPolyfillBundleOptions, createServerMainCodeBundleOptions, createServerPolyfillBundleOptions, createSsrEntryCodeBundleOptions, } from '../../tools/esbuild/application-code-bundle'; import { BundlerContext } from '../../tools/esbuild/bundler-context'; import { createGlobalScriptsBundleOptions } from '../../tools/esbuild/global-scripts'; import { createGlobalStylesBundleOptions } from '../../tools/esbuild/global-styles'; import { getSupportedNodeTargets } from '../../tools/esbuild/target'; import type { NormalizedApplicationBuildOptions } from './options'; /** * Generates one or more BundlerContext instances based on the builder provided * configuration. * @param options The normalized application builder options to use. * @param browsers An string array of browserslist browsers to support. * @param codeBundleCache An instance of the TypeScript source file cache. * @returns An array of BundlerContext objects. */ export function setupBundlerContexts( options: NormalizedApplicationBuildOptions, target: string[], codeBundleCache: SourceFileCache, stylesheetBundler: ComponentStylesheetBundler, angularCompilationContext: AngularCompilationContext, templateUpdates: Map<string, string> | undefined, ): { typescriptContexts: BundlerContext[]; otherContexts: BundlerContext[]; } { const { outputMode, serverEntryPoint, appShellOptions, prerenderOptions, ssrOptions, workspaceRoot, watch = false, } = options; const typescriptContexts = []; const otherContexts = []; // Browser application code typescriptContexts.push( new BundlerContext( workspaceRoot, watch, createBrowserCodeBundleOptions( options, target, codeBundleCache, stylesheetBundler, angularCompilationContext, templateUpdates, ), true, ), ); // Browser polyfills code const browserPolyfillBundleOptions = createBrowserPolyfillBundleOptions( options, target, codeBundleCache, stylesheetBundler, angularCompilationContext.createSecondaryContext(), ); if (browserPolyfillBundleOptions) { const browserPolyfillContext = new BundlerContext( workspaceRoot, watch, browserPolyfillBundleOptions, true, ); if (typeof browserPolyfillBundleOptions === 'function') { otherContexts.push(browserPolyfillContext); } else { typescriptContexts.push(browserPolyfillContext); } } // Global Stylesheets if (options.globalStyles.length > 0) { for (const initial of [true, false]) { const bundleOptions = createGlobalStylesBundleOptions(options, target, initial); if (bundleOptions) { otherContexts.push( new BundlerContext(workspaceRoot, watch, bundleOptions, true, () => initial), ); } } } // Global Scripts if (options.globalScripts.length > 0) { for (const initial of [true, false]) { const bundleOptions = createGlobalScriptsBundleOptions(options, target, initial); if (bundleOptions) { otherContexts.push( new BundlerContext(workspaceRoot, watch, bundleOptions, true, () => initial), ); } } } // Skip server build when none of the features are enabled. if (serverEntryPoint && (outputMode || prerenderOptions || appShellOptions || ssrOptions)) { const nodeTargets = [...target, ...getSupportedNodeTargets()]; typescriptContexts.push( new BundlerContext( workspaceRoot, watch, createServerMainCodeBundleOptions( options, nodeTargets, codeBundleCache, stylesheetBundler, angularCompilationContext.createSecondaryContext(), ), true, ), ); if (outputMode && ssrOptions?.entry) { // New behavior introduced: 'server.ts' is now bundled separately from 'main.server.ts'. typescriptContexts.push( new BundlerContext( workspaceRoot, watch, createSsrEntryCodeBundleOptions( options, nodeTargets, codeBundleCache, stylesheetBundler, angularCompilationContext.createSecondaryContext(), ), true, ), ); } // Server polyfills code const serverPolyfillBundleOptions = createServerPolyfillBundleOptions( options, nodeTargets, codeBundleCache.loadResultCache, ); if (serverPolyfillBundleOptions) { otherContexts.push( new BundlerContext(workspaceRoot, watch, serverPolyfillBundleOptions, true), ); } } return { typescriptContexts, otherContexts }; } export function createComponentStyleBundler( options: NormalizedApplicationBuildOptions, target: string[], ): ComponentStylesheetBundler { const { workspaceRoot, optimizationOptions, sourcemapOptions, outputNames, externalDependencies, preserveSymlinks, stylePreprocessorOptions, inlineStyleLanguage, cacheOptions, tailwindConfiguration, postcssConfiguration, publicPath, } = options; const incremental = !!options.watch; return new ComponentStylesheetBundler( { workspaceRoot, inlineFonts: !!optimizationOptions.fonts.inline, optimization: !!optimizationOptions.styles.minify, sourcemap: // Hidden component stylesheet sourcemaps are inaccessible which is effectively // the same as being disabled. Disabling has the advantage of avoiding the overhead // of sourcemap processing. sourcemapOptions.styles && !sourcemapOptions.hidden ? 'linked' : false, sourcesContent: sourcemapOptions.sourcesContent, outputNames, includePaths: stylePreprocessorOptions?.includePaths, // string[] | undefined' is not assignable to type '(Version | DeprecationOrId)[] | undefined'. // eslint-disable-next-line @typescript-eslint/no-explicit-any sass: stylePreprocessorOptions?.sass as any, externalDependencies, target, preserveSymlinks, tailwindConfiguration, postcssConfiguration, cacheOptions, publicPath, }, inlineStyleLanguage, incremental, ); }