Skip to content
This repository has been archived by the owner on Aug 7, 2021. It is now read-only.

Commit

Permalink
feat: support hidden source maps to map error stack traces from crash…
Browse files Browse the repository at this point in the history
… reports (#854)
  • Loading branch information
Dimitar Tachev authored Apr 10, 2019
1 parent 4e69936 commit dbcfbc2
Show file tree
Hide file tree
Showing 6 changed files with 258 additions and 145 deletions.
13 changes: 13 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,19 @@ exports.getEntryPathRegExp = (appFullPath, entryModule) => {
const escapedPath = entryModuleFullPath.replace(/\\/g, "\\\\");
return new RegExp(escapedPath);
}

exports.getSourceMapFilename = (hiddenSourceMap, appFolderPath, outputPath) => {
const appFolderRelativePath = path.join(path.relative(outputPath, appFolderPath));
let sourceMapFilename = "[file].map";
if (typeof hiddenSourceMap === "string") {
sourceMapFilename = path.join(appFolderRelativePath, hiddenSourceMap, "[file].map");
} else if (typeof hiddenSourceMap === "boolean" && !!hiddenSourceMap) {
sourceMapFilename = path.join(appFolderRelativePath, "sourceMap", "[file].map");
}

return sourceMapFilename;
}

/**
* Converts an array of strings externals to an array of regular expressions.
* Input is an array of string, which we need to convert to regular expressions, so all imports for this module will be treated as externals.
Expand Down
8 changes: 6 additions & 2 deletions templates/webpack.angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ module.exports = env => {
uglify, // --env.uglify
report, // --env.report
sourceMap, // --env.sourceMap
hiddenSourceMap, // --env.hiddenSourceMap
hmr, // --env.hmr,
unitTesting, // --env.unitTesting
} = env;
Expand Down Expand Up @@ -96,6 +97,8 @@ module.exports = env => {
additionalLazyModuleResources: additionalLazyModuleResources
});

let sourceMapFilename = nsWebpack.getSourceMapFilename(hiddenSourceMap, __dirname, dist);

const config = {
mode: uglify ? "production" : "development",
context: appFullPath,
Expand All @@ -112,6 +115,7 @@ module.exports = env => {
output: {
pathinfo: false,
path: dist,
sourceMapFilename,
libraryTarget: "commonjs2",
filename: "[name].js",
globalObject: "global",
Expand Down Expand Up @@ -142,7 +146,7 @@ module.exports = env => {
"fs": "empty",
"__dirname": false,
},
devtool: sourceMap ? "inline-source-map" : "none",
devtool: hiddenSourceMap ? "hidden-source-map" : (sourceMap ? "inline-source-map" : "none"),
optimization: {
runtimeChunk: "single",
splitChunks: {
Expand All @@ -164,7 +168,7 @@ module.exports = env => {
new UglifyJsPlugin({
parallel: true,
cache: true,
sourceMap: !!sourceMap,
sourceMap: !!sourceMap || !!hiddenSourceMap,
uglifyOptions: {
output: {
comments: false,
Expand Down
Loading

0 comments on commit dbcfbc2

Please sign in to comment.