Skip to content

Commit e1398d3

Browse files
committed
perf(@angular-devkit/build-angular): do not inline sourcemap when using vite dev-server
Vite inlines the source map as part of content (https://github.com/vitejs/vite/blob/ba62be40b4f46c98872fb10990b559fee88f4a29/packages/vite/src/node/server/send.ts#L59-L63) with no option to disable this behaviour. While this is improves performances when Vite is used without prebundling. When using prebundling this is causes an overhead as the response can grow drastically, in some cases over 50mb. (cherry picked from commit 3ec8827)
1 parent f74151b commit e1398d3

File tree

1 file changed

+2
-3
lines changed
  • packages/angular_devkit/build_angular/src/builders/dev-server

1 file changed

+2
-3
lines changed

packages/angular_devkit/build_angular/src/builders/dev-server/vite-server.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,12 @@ export async function setupServer(
228228
return;
229229
}
230230

231-
const code = Buffer.from(codeContents).toString('utf-8');
232231
const mapContents = outputFiles.get(file + '.map')?.contents;
233232

234233
return {
235234
// Remove source map URL comments from the code if a sourcemap is present.
236235
// Vite will inline and add an additional sourcemap URL for the sourcemap.
237-
code: mapContents ? code.replace(/^\/\/# sourceMappingURL=[^\r\n]*/gm, '') : code,
236+
code: Buffer.from(codeContents).toString('utf-8'),
238237
map: mapContents && Buffer.from(mapContents).toString('utf-8'),
239238
};
240239
},
@@ -262,7 +261,7 @@ export async function setupServer(
262261
// Resource files are handled directly.
263262
// Global stylesheets (CSS files) are currently considered resources to workaround
264263
// dev server sourcemap issues with stylesheets.
265-
if (extension !== '.js' && extension !== '.html') {
264+
if (extension !== '.html') {
266265
const outputFile = outputFiles.get(parsedUrl.pathname);
267266
if (outputFile) {
268267
const mimeType = lookupMimeType(extension);

0 commit comments

Comments
 (0)