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

feat: support hidden source maps to map error stack traces from crash reports #854

Merged
merged 1 commit into from
Apr 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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