Skip to content

Commit

Permalink
fix: enforce absolute path for server.sourcemapIgnoreList (#12309)
Browse files Browse the repository at this point in the history
Co-authored-by: Bjorn Lu <[email protected]>
  • Loading branch information
patak-dev and bluwy authored Mar 6, 2023
1 parent 5968bec commit ab6ae07
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/config/server-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion packages/vite/src/node/server/transformRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down

0 comments on commit ab6ae07

Please sign in to comment.