diff --git a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/sass-plugin.ts b/packages/angular_devkit/build_angular/src/builders/browser-esbuild/sass-plugin.ts index cd315855b119..0c820f1ffe1a 100644 --- a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/sass-plugin.ts +++ b/packages/angular_devkit/build_angular/src/builders/browser-esbuild/sass-plugin.ts @@ -16,12 +16,10 @@ export function createSassPlugin(options: { sourcemap: boolean; loadPaths?: stri setup(build: PluginBuild): void { let sass: typeof import('sass'); - build.onStart(async () => { - // Lazily load Sass - sass = await import('sass'); - }); + build.onLoad({ filter: /\.s[ac]ss$/ }, async (args) => { + // Lazily load Sass when a Sass file is found + sass ??= await import('sass'); - build.onLoad({ filter: /\.s[ac]ss$/ }, (args) => { try { const warnings: PartialMessage[] = []; // Use sync version as async version is slower.