Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(vite): Ensure sourcemaps are resolved from the correct location with vite serve #63

Merged
merged 2 commits into from
Aug 2, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/vite/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,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/<id>/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',
},
Expand Down