Skip to content

Commit 7fa971d

Browse files
committed
refactor(@angular/build): move component stylesheet bundler out of compiler plugin
The component stylesheet bundler is now created during the setup of the Angular compiler plugin options. This is an initial step to support more fine-grained rebuild actions with the new component stylesheet development server support.
1 parent 94dbacf commit 7fa971d

File tree

3 files changed

+41
-44
lines changed

3 files changed

+41
-44
lines changed

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import {
3030
import { JavaScriptTransformer } from '../javascript-transformer';
3131
import { LoadResultCache, createCachedLoad } from '../load-result-cache';
3232
import { logCumulativeDurations, profileAsync, resetCumulativeDurations } from '../profiling';
33-
import { BundleStylesheetOptions } from '../stylesheets/bundle-options';
3433
import { SharedTSCompilationState, getSharedCompilationState } from './compilation-state';
3534
import { ComponentStylesheetBundler } from './component-stylesheets';
3635
import { FileReferenceTracker } from './file-reference-tracker';
@@ -57,7 +56,7 @@ export interface CompilerPluginOptions {
5756
// eslint-disable-next-line max-lines-per-function
5857
export function createCompilerPlugin(
5958
pluginOptions: CompilerPluginOptions,
60-
styleOptions: BundleStylesheetOptions & { inlineStyleLanguage: string },
59+
stylesheetBundler: ComponentStylesheetBundler,
6160
): Plugin {
6261
return {
6362
name: 'angular-compiler',
@@ -128,12 +127,6 @@ export function createCompilerPlugin(
128127
// Determines if transpilation should be handle by TypeScript or esbuild
129128
let useTypeScriptTranspilation = true;
130129

131-
// Track incremental component stylesheet builds
132-
const stylesheetBundler = new ComponentStylesheetBundler(
133-
styleOptions,
134-
styleOptions.inlineStyleLanguage,
135-
pluginOptions.incremental,
136-
);
137130
let sharedTSCompilationState: SharedTSCompilationState | undefined;
138131

139132
// To fully invalidate files, track resource referenced files and their referencing source

packages/angular/build/src/tools/esbuild/application-code-bundle.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export function createBrowserCodeBundleOptions(
3838
): BuildOptions {
3939
const { entryPoints, outputNames, polyfills } = options;
4040

41-
const { pluginOptions, styleOptions } = createCompilerPluginOptions(
41+
const { pluginOptions, stylesheetBundler } = createCompilerPluginOptions(
4242
options,
4343
target,
4444
sourceFileCache,
@@ -65,8 +65,8 @@ export function createBrowserCodeBundleOptions(
6565
createCompilerPlugin(
6666
// JS/TS options
6767
pluginOptions,
68-
// Component stylesheet options
69-
styleOptions,
68+
// Component stylesheet bundler
69+
stylesheetBundler,
7070
),
7171
],
7272
};
@@ -134,7 +134,7 @@ export function createBrowserPolyfillBundleOptions(
134134
// Only add the Angular TypeScript compiler if TypeScript files are provided in the polyfills
135135
if (hasTypeScriptEntries) {
136136
buildOptions.plugins ??= [];
137-
const { pluginOptions, styleOptions } = createCompilerPluginOptions(
137+
const { pluginOptions, stylesheetBundler } = createCompilerPluginOptions(
138138
options,
139139
target,
140140
sourceFileCache,
@@ -144,7 +144,7 @@ export function createBrowserPolyfillBundleOptions(
144144
// JS/TS options
145145
{ ...pluginOptions, noopTypeScriptCompilation: true },
146146
// Component stylesheet options are unused for polyfills but required by the plugin
147-
styleOptions,
147+
stylesheetBundler,
148148
),
149149
);
150150
}
@@ -243,7 +243,7 @@ export function createServerMainCodeBundleOptions(
243243
'createServerCodeBundleOptions should not be called without a defined serverEntryPoint.',
244244
);
245245

246-
const { pluginOptions, styleOptions } = createCompilerPluginOptions(
246+
const { pluginOptions, stylesheetBundler } = createCompilerPluginOptions(
247247
options,
248248
target,
249249
sourceFileCache,
@@ -278,8 +278,8 @@ export function createServerMainCodeBundleOptions(
278278
createCompilerPlugin(
279279
// JS/TS options
280280
{ ...pluginOptions, noopTypeScriptCompilation: true },
281-
// Component stylesheet options
282-
styleOptions,
281+
// Component stylesheet bundler
282+
stylesheetBundler,
283283
),
284284
],
285285
};
@@ -382,7 +382,7 @@ export function createSsrEntryCodeBundleOptions(
382382
'createSsrEntryCodeBundleOptions should not be called without a defined serverEntryPoint.',
383383
);
384384

385-
const { pluginOptions, styleOptions } = createCompilerPluginOptions(
385+
const { pluginOptions, stylesheetBundler } = createCompilerPluginOptions(
386386
options,
387387
target,
388388
sourceFileCache,
@@ -411,8 +411,8 @@ export function createSsrEntryCodeBundleOptions(
411411
createCompilerPlugin(
412412
// JS/TS options
413413
{ ...pluginOptions, noopTypeScriptCompilation: true },
414-
// Component stylesheet options
415-
styleOptions,
414+
// Component stylesheet bundler
415+
stylesheetBundler,
416416
),
417417
],
418418
inject,

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

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import { NormalizedApplicationBuildOptions } from '../../builders/application/options';
1010
import type { createCompilerPlugin } from './angular/compiler-plugin';
11+
import { ComponentStylesheetBundler } from './angular/component-stylesheets';
1112
import type { SourceFileCache } from './angular/source-file-cache';
1213

1314
type CreateCompilerPluginParameters = Parameters<typeof createCompilerPlugin>;
@@ -18,7 +19,7 @@ export function createCompilerPluginOptions(
1819
sourceFileCache?: SourceFileCache,
1920
): {
2021
pluginOptions: CreateCompilerPluginParameters[0];
21-
styleOptions: CreateCompilerPluginParameters[1];
22+
stylesheetBundler: ComponentStylesheetBundler;
2223
} {
2324
const {
2425
workspaceRoot,
@@ -40,6 +41,7 @@ export function createCompilerPluginOptions(
4041
externalRuntimeStyles,
4142
instrumentForCoverage,
4243
} = options;
44+
const incremental = !!options.watch;
4345

4446
return {
4547
// JS/TS options
@@ -52,33 +54,35 @@ export function createCompilerPluginOptions(
5254
fileReplacements,
5355
sourceFileCache,
5456
loadResultCache: sourceFileCache?.loadResultCache,
55-
incremental: !!options.watch,
57+
incremental,
5658
externalRuntimeStyles,
5759
instrumentForCoverage,
5860
},
59-
// Component stylesheet options
60-
styleOptions: {
61-
workspaceRoot,
62-
inlineFonts: !!optimizationOptions.fonts.inline,
63-
optimization: !!optimizationOptions.styles.minify,
64-
sourcemap:
65-
// Hidden component stylesheet sourcemaps are inaccessible which is effectively
66-
// the same as being disabled. Disabling has the advantage of avoiding the overhead
67-
// of sourcemap processing.
68-
sourcemapOptions.styles && !sourcemapOptions.hidden ? 'linked' : false,
69-
outputNames,
70-
includePaths: stylePreprocessorOptions?.includePaths,
71-
// string[] | undefined' is not assignable to type '(Version | DeprecationOrId)[] | undefined'.
72-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
73-
sass: stylePreprocessorOptions?.sass as any,
74-
externalDependencies,
75-
target,
61+
stylesheetBundler: new ComponentStylesheetBundler(
62+
{
63+
workspaceRoot,
64+
inlineFonts: !!optimizationOptions.fonts.inline,
65+
optimization: !!optimizationOptions.styles.minify,
66+
sourcemap:
67+
// Hidden component stylesheet sourcemaps are inaccessible which is effectively
68+
// the same as being disabled. Disabling has the advantage of avoiding the overhead
69+
// of sourcemap processing.
70+
sourcemapOptions.styles && !sourcemapOptions.hidden ? 'linked' : false,
71+
outputNames,
72+
includePaths: stylePreprocessorOptions?.includePaths,
73+
// string[] | undefined' is not assignable to type '(Version | DeprecationOrId)[] | undefined'.
74+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
75+
sass: stylePreprocessorOptions?.sass as any,
76+
externalDependencies,
77+
target,
78+
preserveSymlinks,
79+
tailwindConfiguration,
80+
postcssConfiguration,
81+
cacheOptions,
82+
publicPath,
83+
},
7684
inlineStyleLanguage,
77-
preserveSymlinks,
78-
tailwindConfiguration,
79-
postcssConfiguration,
80-
cacheOptions,
81-
publicPath,
82-
},
85+
incremental,
86+
),
8387
};
8488
}

0 commit comments

Comments
 (0)