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

feat: add sourcemapIgnoreList configuration option #12174

Merged
merged 8 commits into from
Mar 1, 2023
17 changes: 17 additions & 0 deletions docs/config/server-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,3 +318,20 @@ export default defineConfig({
},
})
```

## server.sourcemapIgnoreList

- **Type:** `(sourcePath: string, sourcemapPath: string) => boolean`
danielroe marked this conversation as resolved.
Show resolved Hide resolved
- **Default:** `(sourcePath) => sourcePath.includes('/node_modules/')`

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).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bmeurer not blocking for the PR, but it would be nice to be able to link to a more focused blog post about x_google_ignoreList. If your team ends up having a better resource in the future, would you do a PR to rewire these references?

Copy link
Contributor

@jecfish jecfish Mar 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to this, I will draft something up and send another PR to update it. Thanks for calling that out!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jecfish, sounds great!


```js
export default defineConfig({
server: {
// This is the default value, and will add all files with node_modules in their paths
// to the ignore list.
sourcemapIgnoreList: (sourcePath, sourcemapPath) => sourcePath.includes('/node_modules/')
danielroe marked this conversation as resolved.
Show resolved Hide resolved
}
};
```
10 changes: 9 additions & 1 deletion packages/vite/src/node/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ export interface ServerOptions extends CommonServerOptions {
* @default true
*/
preTransformRequests?: boolean
/**
* Whether or not to ignore-list source files in the dev 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).
* By default, it excludes all paths containing `/node_modules/`.
*/
sourcemapIgnoreList?: (sourcePath: string, sourcemapPath: string) => boolean
danielroe marked this conversation as resolved.
Show resolved Hide resolved
/**
* Force dep pre-optimization regardless of whether deps have changed.
*
Expand All @@ -127,6 +133,7 @@ export interface ServerOptions extends CommonServerOptions {
export interface ResolvedServerOptions extends ServerOptions {
fs: Required<FileSystemServeOptions>
middlewareMode: boolean
sourcemapIgnoreList: NonNullable<ServerOptions['sourcemapIgnoreList']>
}

export interface FileSystemServeOptions {
Expand Down Expand Up @@ -746,7 +753,8 @@ export function resolveServerOptions(
): ResolvedServerOptions {
const server: ResolvedServerOptions = {
preTransformRequests: true,
...(raw as ResolvedServerOptions),
sourcemapIgnoreList: (sourcePath) => sourcePath.includes('/node_modules/'),
danielroe marked this conversation as resolved.
Show resolved Hide resolved
...(raw as Omit<ResolvedServerOptions, 'sourcemapIgnoreList'>),
middlewareMode: !!raw?.middlewareMode,
}
let allowDirs = server.fs?.allow
Expand Down
17 changes: 17 additions & 0 deletions packages/vite/src/node/server/transformRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,23 @@ async function loadAndTransform(
) {
const sourcePath = map.sources[sourcesIndex]

const sourcemapPath = `${mod.file}.map`
const ignoreList = config.server.sourcemapIgnoreList(
sourcePath,
sourcemapPath,
)
if (typeof ignoreList !== 'boolean') {
logger.warn('sourcemapIgnoreList function must return a boolean.')
}
if (ignoreList) {
if (map.x_google_ignoreList === undefined) {
map.x_google_ignoreList = []
}
if (!map.x_google_ignoreList.includes(sourcesIndex)) {
map.x_google_ignoreList.push(sourcesIndex)
}
}

// Rewrite sources to relative paths to give debuggers the chance
// to resolve and display them in a meaningful way (rather than
// with absolute paths).
Expand Down