Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uglify Sourcemap improvements #875

Merged
merged 3 commits into from
Feb 21, 2018
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Faster uglify sourcemaps
Use raw mappings rather than generating and parsing the sourcemap from uglify.
devongovett committed Feb 21, 2018
commit 8e8a60ea17e635ca9982e62aa149c530e98b2f5c
29 changes: 24 additions & 5 deletions src/transforms/uglify.js
Original file line number Diff line number Diff line change
@@ -8,12 +8,32 @@ module.exports = async function(asset) {
let source = (await asset.generate()).js;

let customConfig = await asset.getConfig(['.uglifyrc']);
let sourceMap = asset.options.sourceMap && new SourceMap();
let options = {
warnings: true,
mangle: {
toplevel: true
},
sourceMap: asset.options.sourceMaps ? {filename: asset.relativeName} : false
output: sourceMap
? {
source_map: {
add(source, gen_line, gen_col, orig_line, orig_col, name) {
sourceMap.addMapping({
source,
name,
original: {
line: orig_line,
column: orig_col
},
generated: {
line: gen_line,
column: gen_col
}
});
}
}
}
: {}
};

if (customConfig) {
@@ -26,15 +46,14 @@ module.exports = async function(asset) {
throw result.error;
}

if (result.map) {
result.map = await new SourceMap().addMap(JSON.parse(result.map));
if (sourceMap) {
if (asset.sourceMap) {
asset.sourceMap = await new SourceMap().extendSourceMap(
asset.sourceMap,
result.map
sourceMap
);
} else {
asset.sourceMap = result.map;
asset.sourceMap = sourceMap;
}
}