Skip to content

Commit aae34fc

Browse files
clydinangular-robot[bot]
authored andcommitted
perf(@angular-devkit/build-angular): fully lazy load sass in esbuild builder
When using the esbuild-based browser application builder, the Sass worker pool import is now lazy to prevent unnecessary module loading when Sass is not used within an application.
1 parent 59b7d71 commit aae34fc

File tree

1 file changed

+5
-2
lines changed
  • packages/angular_devkit/build_angular/src/builders/browser-esbuild

1 file changed

+5
-2
lines changed

packages/angular_devkit/build_angular/src/builders/browser-esbuild/sass-plugin.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { readFile } from 'node:fs/promises';
1212
import { dirname, extname, join, relative } from 'node:path';
1313
import { fileURLToPath, pathToFileURL } from 'node:url';
1414
import type { CompileResult, Exception, Syntax } from 'sass';
15-
import {
15+
import type {
1616
FileImporterWithRequestContextOptions,
1717
SassWorkerImplementation,
1818
} from '../../sass/sass-service';
@@ -93,7 +93,10 @@ async function compileString(
9393
resolveUrl: (url: string, previousResolvedModules?: Set<string>) => Promise<ResolveResult>,
9494
): Promise<OnLoadResult> {
9595
// Lazily load Sass when a Sass file is found
96-
sassWorkerPool ??= new SassWorkerImplementation(true);
96+
if (sassWorkerPool === undefined) {
97+
const sassService = await import('../../sass/sass-service');
98+
sassWorkerPool = new sassService.SassWorkerImplementation(true);
99+
}
97100

98101
const warnings: PartialMessage[] = [];
99102
try {

0 commit comments

Comments
 (0)