From 4c251853fbc66c6c9aae171dc75612db31afe2fb Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Tue, 23 Aug 2022 13:18:19 -0400 Subject: [PATCH] perf(@angular-devkit/build-angular): avoid extra string creation with no sourcemaps for esbuild sass When using the experimental esbuild-based browser application builder with Sass stylesheets, an additional string creation for each output stylesheet will now be avoided when sourcemaps are disabled. (cherry picked from commit a910ae992c94c0987a2f3f5ea0c77173d8e4233d) --- .../src/builders/browser-esbuild/sass-plugin.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) 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 a6238493f827..cd315855b119 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 @@ -42,7 +42,7 @@ export function createSassPlugin(options: { sourcemap: boolean; loadPaths?: stri return { loader: 'css', - contents: `${css}\n${sourceMapToUrlComment(sourceMap)}`, + contents: sourceMap ? `${css}\n${sourceMapToUrlComment(sourceMap)}` : css, watchFiles: loadedUrls.map((url) => fileURLToPath(url)), warnings, }; @@ -68,11 +68,7 @@ export function createSassPlugin(options: { sourcemap: boolean; loadPaths?: stri }; } -function sourceMapToUrlComment(sourceMap: CompileResult['sourceMap']): string { - if (!sourceMap) { - return ''; - } - +function sourceMapToUrlComment(sourceMap: Exclude): string { const urlSourceMap = Buffer.from(JSON.stringify(sourceMap), 'utf-8').toString('base64'); return `/*# sourceMappingURL=data:application/json;charset=utf-8;base64,${urlSourceMap} */`;