From ab6ae073e4feabeb78cec8b56af527d42b79415e Mon Sep 17 00:00:00 2001 From: patak Date: Mon, 6 Mar 2023 19:49:19 +0100 Subject: [PATCH] fix: enforce absolute path for server.sourcemapIgnoreList (#12309) Co-authored-by: Bjorn Lu --- docs/config/server-options.md | 2 ++ packages/vite/src/node/server/transformRequest.ts | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/config/server-options.md b/docs/config/server-options.md index f10cca7ce1db61..4e0ef58ac1f0f7 100644 --- a/docs/config/server-options.md +++ b/docs/config/server-options.md @@ -326,6 +326,8 @@ export default defineConfig({ Whether or not to ignore source files in the server sourcemap, used to populate the [`x_google_ignoreList` source map extension](https://developer.chrome.com/blog/devtools-better-angular-debugging/#the-x_google_ignorelist-source-map-extension). +`server.sourcemapIgnoreList` is the equivalent of [build.rollupOptions.output.sourcemapIgnoreList](https://rollupjs.org/configuration-options/#output-sourcemapignorelist) for the dev server. A difference between the two config options is that the rollup function is called with a relative path for `sourcePath` while `server.sourcemapIgnoreList` is called with an absolute path. During dev, most modules have the map and the source in the same folder, so the relative path for `sourcePath` is the file name itself. In these cases, absolute paths makes it convenient to be used instead. + By default, it excludes all paths containing `node_modules`. You can pass `false` to disable this behavior, or, for full control, a function that takes the source path and sourcemap path and returns whether to ignore the source path. ```js diff --git a/packages/vite/src/node/server/transformRequest.ts b/packages/vite/src/node/server/transformRequest.ts index 1bc34fa4d73888..36141f58017aa2 100644 --- a/packages/vite/src/node/server/transformRequest.ts +++ b/packages/vite/src/node/server/transformRequest.ts @@ -281,7 +281,9 @@ async function loadAndTransform( const sourcemapPath = `${mod.file}.map` const ignoreList = config.server.sourcemapIgnoreList( - sourcePath, + path.isAbsolute(sourcePath) + ? sourcePath + : path.resolve(path.dirname(sourcemapPath), sourcePath), sourcemapPath, ) if (typeof ignoreList !== 'boolean') {