Skip to content

Commit d600957

Browse files
kpdeckerarunoda
authored andcommitted
Add node trace source map handling in dev mode (vercel#2816)
* Add node trace source map handling in dev mode Fixes vercel#2285 * Fix typo in comment
1 parent 4ee0dc9 commit d600957

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

server/build/webpack.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,23 @@ export default async function createCompiler (dir, { dev = false, quiet = false,
247247
inputSourceMap: sourceMap
248248
})
249249

250+
// Strip ?entry to map back to filesystem and work with iTerm, etc.
251+
let { map } = transpiled
252+
let output = transpiled.code
253+
254+
if (map) {
255+
map.sources = map.sources.map((source) => source.replace(/\?entry/, ''))
256+
delete map.sourcesContent
257+
258+
// Output explicit inline source map that source-map-support can pickup via requireHook mode.
259+
// Since these are not formal chunks, the devtool infrastructure in webpack does not output
260+
// a source map for these files.
261+
const sourceMapUrl = new Buffer(JSON.stringify(map), 'utf-8').toString('base64')
262+
output = `${output}\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,${sourceMapUrl}`
263+
}
264+
250265
return {
251-
content: transpiled.code,
266+
content: output,
252267
sourceMap: transpiled.map
253268
}
254269
}

server/index.js

+8
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ const blockedPages = {
2929

3030
export default class Server {
3131
constructor ({ dir = '.', dev = false, staticMarkup = false, quiet = false, conf = null } = {}) {
32+
// When in dev mode, remap the inline source maps that we generate within the webpack portion
33+
// of the build.
34+
if (dev) {
35+
require('source-map-support').install({
36+
hookRequire: true
37+
})
38+
}
39+
3240
this.dir = resolve(dir)
3341
this.dev = dev
3442
this.quiet = quiet

0 commit comments

Comments
 (0)