Skip to content

Commit ac8f81e

Browse files
committed
refactor(@angular/build): reduce inline style language value per call usage
The configured inline style language for Angular components is now set during the construction of the component stylesheet bundler. This avoids needing to repeatedly pass the value into each inline bundling call. The ability to customize the language per call is retained to allow individual style control if needed.
1 parent c48d694 commit ac8f81e

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

packages/angular/build/src/tools/esbuild/angular/compiler-plugin.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ export function createCompilerPlugin(
130130
// Track incremental component stylesheet builds
131131
const stylesheetBundler = new ComponentStylesheetBundler(
132132
styleOptions,
133+
styleOptions.inlineStyleLanguage,
133134
pluginOptions.incremental,
134135
);
135136
let sharedTSCompilationState: SharedTSCompilationState | undefined;
@@ -190,8 +191,8 @@ export function createCompilerPlugin(
190191
stylesheetResult = await stylesheetBundler.bundleInline(
191192
data,
192193
containingFile,
193-
// Inline stylesheets from a template style element are always CSS
194-
containingFile.endsWith('.html') ? 'css' : styleOptions.inlineStyleLanguage,
194+
// Inline stylesheets from a template style element are always CSS; Otherwise, use default.
195+
containingFile.endsWith('.html') ? 'css' : undefined,
195196
// When external runtime styles are enabled, an identifier for the style that does not change
196197
// based on the content is required to avoid emitted JS code changes. Any JS code changes will
197198
// invalid the output and force a full page reload for HMR cases. The containing file and order
@@ -490,7 +491,6 @@ export function createCompilerPlugin(
490491
build,
491492
stylesheetBundler,
492493
additionalResults,
493-
styleOptions.inlineStyleLanguage,
494494
pluginOptions.loadResultCache,
495495
);
496496
}

packages/angular/build/src/tools/esbuild/angular/component-stylesheets.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export class ComponentStylesheetBundler {
3333
*/
3434
constructor(
3535
private readonly options: BundleStylesheetOptions,
36+
private readonly defaultInlineLanguage: string,
3637
private readonly incremental: boolean,
3738
) {}
3839

@@ -63,7 +64,12 @@ export class ComponentStylesheetBundler {
6364
);
6465
}
6566

66-
async bundleInline(data: string, filename: string, language: string, externalId?: string) {
67+
async bundleInline(
68+
data: string,
69+
filename: string,
70+
language = this.defaultInlineLanguage,
71+
externalId?: string,
72+
) {
6773
// Use a hash of the inline stylesheet content to ensure a consistent identifier. External stylesheets will resolve
6874
// to the actual stylesheet file path.
6975
// TODO: Consider xxhash instead for hashing

packages/angular/build/src/tools/esbuild/angular/jit-plugin-callbacks.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ export function setupJitPluginCallbacks(
6666
build: PluginBuild,
6767
stylesheetBundler: ComponentStylesheetBundler,
6868
additionalResultFiles: Map<string, { outputFiles?: OutputFile[]; metafile?: Metafile }>,
69-
inlineStyleLanguage: string,
7069
loadCache?: LoadResultCache,
7170
): void {
7271
const root = build.initialOptions.absWorkingDir ?? '';
@@ -114,11 +113,7 @@ export function setupJitPluginCallbacks(
114113
if (entry.contents === undefined) {
115114
stylesheetResult = await stylesheetBundler.bundleFile(entry.path);
116115
} else {
117-
stylesheetResult = await stylesheetBundler.bundleInline(
118-
entry.contents,
119-
entry.path,
120-
inlineStyleLanguage,
121-
);
116+
stylesheetResult = await stylesheetBundler.bundleInline(entry.contents, entry.path);
122117
}
123118

124119
const { contents, outputFiles, errors, warnings, metafile, referencedFiles } =

0 commit comments

Comments
 (0)