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

Commit dbcfbc2

Browse files
author
Dimitar Tachev
authored
feat: support hidden source maps to map error stack traces from crash reports (#854)
1 parent 4e69936 commit dbcfbc2

6 files changed

+258
-145
lines changed

Diff for: index.js

+13
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,19 @@ exports.getEntryPathRegExp = (appFullPath, entryModule) => {
6666
const escapedPath = entryModuleFullPath.replace(/\\/g, "\\\\");
6767
return new RegExp(escapedPath);
6868
}
69+
70+
exports.getSourceMapFilename = (hiddenSourceMap, appFolderPath, outputPath) => {
71+
const appFolderRelativePath = path.join(path.relative(outputPath, appFolderPath));
72+
let sourceMapFilename = "[file].map";
73+
if (typeof hiddenSourceMap === "string") {
74+
sourceMapFilename = path.join(appFolderRelativePath, hiddenSourceMap, "[file].map");
75+
} else if (typeof hiddenSourceMap === "boolean" && !!hiddenSourceMap) {
76+
sourceMapFilename = path.join(appFolderRelativePath, "sourceMap", "[file].map");
77+
}
78+
79+
return sourceMapFilename;
80+
}
81+
6982
/**
7083
* Converts an array of strings externals to an array of regular expressions.
7184
* 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.

Diff for: templates/webpack.angular.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ module.exports = env => {
4747
uglify, // --env.uglify
4848
report, // --env.report
4949
sourceMap, // --env.sourceMap
50+
hiddenSourceMap, // --env.hiddenSourceMap
5051
hmr, // --env.hmr,
5152
unitTesting, // --env.unitTesting
5253
} = env;
@@ -96,6 +97,8 @@ module.exports = env => {
9697
additionalLazyModuleResources: additionalLazyModuleResources
9798
});
9899

100+
let sourceMapFilename = nsWebpack.getSourceMapFilename(hiddenSourceMap, __dirname, dist);
101+
99102
const config = {
100103
mode: uglify ? "production" : "development",
101104
context: appFullPath,
@@ -112,6 +115,7 @@ module.exports = env => {
112115
output: {
113116
pathinfo: false,
114117
path: dist,
118+
sourceMapFilename,
115119
libraryTarget: "commonjs2",
116120
filename: "[name].js",
117121
globalObject: "global",
@@ -142,7 +146,7 @@ module.exports = env => {
142146
"fs": "empty",
143147
"__dirname": false,
144148
},
145-
devtool: sourceMap ? "inline-source-map" : "none",
149+
devtool: hiddenSourceMap ? "hidden-source-map" : (sourceMap ? "inline-source-map" : "none"),
146150
optimization: {
147151
runtimeChunk: "single",
148152
splitChunks: {
@@ -164,7 +168,7 @@ module.exports = env => {
164168
new UglifyJsPlugin({
165169
parallel: true,
166170
cache: true,
167-
sourceMap: !!sourceMap,
171+
sourceMap: !!sourceMap || !!hiddenSourceMap,
168172
uglifyOptions: {
169173
output: {
170174
comments: false,

0 commit comments

Comments
 (0)