Skip to content

Commit f875580

Browse files
authoredMar 1, 2023
feat: add sourcemapIgnoreList configuration option (#12174)
1 parent e3f725f commit f875580

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed
 

‎docs/config/server-options.md

+19
Original file line numberDiff line numberDiff line change
@@ -318,3 +318,22 @@ export default defineConfig({
318318
},
319319
})
320320
```
321+
322+
## server.sourcemapIgnoreList
323+
324+
- **Type:** `false | (sourcePath: string, sourcemapPath: string) => boolean`
325+
- **Default:** `(sourcePath) => sourcePath.includes('node_modules')`
326+
327+
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).
328+
329+
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.
330+
331+
```js
332+
export default defineConfig({
333+
server: {
334+
// This is the default value, and will add all files with node_modules in their paths
335+
// to the ignore list.
336+
sourcemapIgnoreList: (sourcePath, sourcemapPath) => sourcePath.includes('node_modules')
337+
}
338+
};
339+
```

‎packages/vite/src/node/server/index.ts

+21-1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,17 @@ export interface ServerOptions extends CommonServerOptions {
115115
* @default true
116116
*/
117117
preTransformRequests?: boolean
118+
/**
119+
* Whether or not to ignore-list source files in the dev server sourcemap, used to populate
120+
* the [`x_google_ignoreList` source map extension](https://developer.chrome.com/blog/devtools-better-angular-debugging/#the-x_google_ignorelist-source-map-extension).
121+
*
122+
* By default, it excludes all paths containing `node_modules`. You can pass `false` to
123+
* disable this behavior, or, for full control, a function that takes the source path and
124+
* sourcemap path and returns whether to ignore the source path.
125+
*/
126+
sourcemapIgnoreList?:
127+
| false
128+
| ((sourcePath: string, sourcemapPath: string) => boolean)
118129
/**
119130
* Force dep pre-optimization regardless of whether deps have changed.
120131
*
@@ -127,6 +138,10 @@ export interface ServerOptions extends CommonServerOptions {
127138
export interface ResolvedServerOptions extends ServerOptions {
128139
fs: Required<FileSystemServeOptions>
129140
middlewareMode: boolean
141+
sourcemapIgnoreList: Exclude<
142+
ServerOptions['sourcemapIgnoreList'],
143+
false | undefined
144+
>
130145
}
131146

132147
export interface FileSystemServeOptions {
@@ -746,7 +761,12 @@ export function resolveServerOptions(
746761
): ResolvedServerOptions {
747762
const server: ResolvedServerOptions = {
748763
preTransformRequests: true,
749-
...(raw as ResolvedServerOptions),
764+
...(raw as Omit<ResolvedServerOptions, 'sourcemapIgnoreList'>),
765+
sourcemapIgnoreList:
766+
raw?.sourcemapIgnoreList === false
767+
? () => false
768+
: raw?.sourcemapIgnoreList ||
769+
((sourcePath) => sourcePath.includes('node_modules')),
750770
middlewareMode: !!raw?.middlewareMode,
751771
}
752772
let allowDirs = server.fs?.allow

‎packages/vite/src/node/server/transformRequest.ts

+17
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,23 @@ async function loadAndTransform(
278278
) {
279279
const sourcePath = map.sources[sourcesIndex]
280280

281+
const sourcemapPath = `${mod.file}.map`
282+
const ignoreList = config.server.sourcemapIgnoreList(
283+
sourcePath,
284+
sourcemapPath,
285+
)
286+
if (typeof ignoreList !== 'boolean') {
287+
logger.warn('sourcemapIgnoreList function must return a boolean.')
288+
}
289+
if (ignoreList) {
290+
if (map.x_google_ignoreList === undefined) {
291+
map.x_google_ignoreList = []
292+
}
293+
if (!map.x_google_ignoreList.includes(sourcesIndex)) {
294+
map.x_google_ignoreList.push(sourcesIndex)
295+
}
296+
}
297+
281298
// Rewrite sources to relative paths to give debuggers the chance
282299
// to resolve and display them in a meaningful way (rather than
283300
// with absolute paths).

0 commit comments

Comments
 (0)
Please sign in to comment.