Skip to content

Commit

Permalink
perf(@angular-devkit/build-angular): avoid extra string creation with…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
clydin authored and dgp1130 committed Aug 23, 2022
1 parent 823852d commit a910ae9
Showing 1 changed file with 2 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -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<CompileResult['sourceMap'], undefined>): string {
const urlSourceMap = Buffer.from(JSON.stringify(sourceMap), 'utf-8').toString('base64');

return `/*# sourceMappingURL=data:application/json;charset=utf-8;base64,${urlSourceMap} */`;
Expand Down

0 comments on commit a910ae9

Please sign in to comment.