From d600957aeb347d4337280c78d8ebdea3f256ce60 Mon Sep 17 00:00:00 2001 From: Kevin Decker Date: Wed, 30 Aug 2017 05:49:40 -0500 Subject: [PATCH] Add node trace source map handling in dev mode (#2816) * Add node trace source map handling in dev mode Fixes #2285 * Fix typo in comment --- server/build/webpack.js | 17 ++++++++++++++++- server/index.js | 8 ++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/server/build/webpack.js b/server/build/webpack.js index 8ce71291..7fd93d57 100644 --- a/server/build/webpack.js +++ b/server/build/webpack.js @@ -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 } } diff --git a/server/index.js b/server/index.js index 7ddce95c..1900ccfd 100644 --- a/server/index.js +++ b/server/index.js @@ -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