Skip to content

Commit

Permalink
ncc build -s to auto-include sourcemap-register in build (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford authored and rauchg committed Feb 1, 2019
1 parent 8cb9e56 commit 0a9014e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
3 changes: 0 additions & 3 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,6 @@ async function runCmd (argv, stdout, stderr) {
if (nodeModulesDir)
fs.symlinkSync(nodeModulesDir, outDir + "/node_modules", "junction");
ps = require("child_process").fork(outDir + "/index.js", {
execArgv: map
? ["-r", resolve(__dirname, "sourcemap-register")]
: [],
stdio: api ? 'pipe' : 'inherit'
});
if (api) {
Expand Down
9 changes: 8 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ module.exports = (
assetPermissions: undefined
};
assetState.assetNames[filename] = true;
if (sourceMap)
if (sourceMap) {
assetState.assetNames[filename + '.map'] = true;
assetState.assetNames['sourcemap-register.js'] = true;
}
nodeLoader.setAssetState(assetState);
relocateLoader.setAssetState(assetState);
// add TsconfigPathsPlugin to support `paths` resolution in tsconfig
Expand Down Expand Up @@ -344,6 +346,11 @@ module.exports = (
map.mappings = ";" + map.mappings;
}

if (map) {
code = `require('./sourcemap-register.js');` + code;
assets['sourcemap-register.js'] = { source: fs.readFileSync(__dirname + "/sourcemap-register.js.cache.js"), permissions: 0o666 };
}

return { code, map, assets };
}
};
Expand Down
1 change: 1 addition & 0 deletions src/sourcemap-register.js.cache.js

0 comments on commit 0a9014e

Please sign in to comment.