From cabba4d249b7262bf0146b89757202aae01549a5 Mon Sep 17 00:00:00 2001 From: Jonathan Romano Date: Fri, 29 Jul 2022 19:15:57 -0400 Subject: [PATCH] Fix sourcemaps with vite serve --- packages/vite/src/index.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/vite/src/index.ts b/packages/vite/src/index.ts index 683eadb..06f46d8 100644 --- a/packages/vite/src/index.ts +++ b/packages/vite/src/index.ts @@ -52,6 +52,20 @@ export default function getConfig( { ...typescriptPlugin({ tsconfig: 'tsconfig.build.json', + tsconfigOverride: { + compilerOptions: { + // rollup-plugin-tsconfig2 runs typescript in a cache directory, so the paths to the source + // files in the emitted sourcemap will be incorrect (since it will be a relative path from + // node_modules/.cache/rollup-plugin-typescript2//placeholder/ instead of dist/ where the + // sourcemap actually is). + // Rollup handles this fine due to the way it merges chained source maps, so everything is fine + // with `vite build`, but `vite serve` eschews rollup and does its source map merging differently, + // leaving the incorrect source resolution intact. + // To get around this, we'll tell typescript how to resolve source file locations + // See https://github.com/ezolenko/rollup-plugin-typescript2/issues/407 + sourceRoot: '../src', + }, + }, }), enforce: 'pre', },