Skip to content

Commit

Permalink
Add node trace source map handling in dev mode (#2816)
Browse files Browse the repository at this point in the history
* Add node trace source map handling in dev mode

Fixes #2285

* Fix typo in comment
  • Loading branch information
kpdecker authored and arunoda committed Aug 30, 2017
1 parent 4ee0dc9 commit d600957
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
17 changes: 16 additions & 1 deletion server/build/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,23 @@ export default async function createCompiler (dir, { dev = false, quiet = false,
inputSourceMap: sourceMap
})

// Strip ?entry to map back to filesystem and work with iTerm, etc.
let { map } = transpiled
let output = transpiled.code

if (map) {
map.sources = map.sources.map((source) => source.replace(/\?entry/, ''))
delete map.sourcesContent

// Output explicit inline source map that source-map-support can pickup via requireHook mode.
// Since these are not formal chunks, the devtool infrastructure in webpack does not output
// a source map for these files.
const sourceMapUrl = new Buffer(JSON.stringify(map), 'utf-8').toString('base64')
output = `${output}\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,${sourceMapUrl}`
}

return {
content: transpiled.code,
content: output,
sourceMap: transpiled.map
}
}
Expand Down
8 changes: 8 additions & 0 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ const blockedPages = {

export default class Server {
constructor ({ dir = '.', dev = false, staticMarkup = false, quiet = false, conf = null } = {}) {
// When in dev mode, remap the inline source maps that we generate within the webpack portion
// of the build.
if (dev) {
require('source-map-support').install({
hookRequire: true
})
}

this.dir = resolve(dir)
this.dev = dev
this.quiet = quiet
Expand Down

0 comments on commit d600957

Please sign in to comment.