-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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 sourcemaps support #617
Merged
Merged
Changes from 12 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
d926f72
add findClosest to SourceMap
DeMoorJasper e58ec8e
remove useless check
DeMoorJasper 7e53e98
add no-source-maps cli flag
DeMoorJasper 23dc55c
Merge branch 'master' into feature/uglify-sourcemaps
64f040a
Merge branch 'feature/uglify-sourcemaps' of github.com:parcel-bundler…
DeMoorJasper 1d72819
fix tests
DeMoorJasper f740716
Merge branch 'master' into feature/uglify-sourcemaps
9ae15c7
Merge branch 'feature/uglify-sourcemaps' of github.com:parcel-bundler…
DeMoorJasper 5c83a79
fix test
DeMoorJasper 02c4097
Merge branch 'master' into feature/uglify-sourcemaps
1afcb95
Merge branch 'feature/uglify-sourcemaps' of github.com:parcel-bundler…
DeMoorJasper 6ac1ec3
bugfix
DeMoorJasper 8eac6de
remove uglify warnings
DeMoorJasper 0a4db4d
minor changes
DeMoorJasper 9ac53b7
Merge pull request #870 from parcel-bundler/master
5d3b8b0
node 6 fix
DeMoorJasper c25f9bc
Merge branch 'feature/uglify-sourcemaps' of github.com:parcel-bundler…
DeMoorJasper 7f20f12
SourceMap bugfixes
devongovett 8e8a60e
Faster uglify sourcemaps
devongovett c51f834
prettier is not prettier
devongovett 59436cd
Merge pull request #875 from parcel-bundler/sourcemap-improvements
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
const {minify} = require('uglify-es'); | ||
const SourceMap = require('../SourceMap'); | ||
const logger = require('../Logger'); | ||
|
||
module.exports = async function(asset) { | ||
await asset.parseIfNeeded(); | ||
|
@@ -11,18 +13,39 @@ module.exports = async function(asset) { | |
warnings: true, | ||
mangle: { | ||
toplevel: true | ||
} | ||
}, | ||
sourceMap: asset.options.sourceMaps ? {filename: asset.relativeName} : false | ||
}; | ||
|
||
if (customConfig) { | ||
options = Object.assign(options, customConfig); | ||
} | ||
|
||
let result = minify(code, options); | ||
|
||
if (result.error) { | ||
throw result.error; | ||
} | ||
|
||
if (result.map) { | ||
result.map = await new SourceMap().addMap(JSON.parse(result.map)); | ||
if (asset.sourceMap) { | ||
asset.sourceMap = await new SourceMap().extendSourceMap( | ||
asset.sourceMap, | ||
result.map | ||
); | ||
} else { | ||
asset.sourceMap = result.map; | ||
} | ||
} | ||
|
||
// Log all warnings | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rather not log all of these. Uglify logs a lot of warnings and they are pretty much useless. I removed this in master already. |
||
if (result.warnings) { | ||
result.warnings.forEach(warning => { | ||
logger.warn('[uglify] ' + warning); | ||
}); | ||
} | ||
|
||
// babel-generator did our code generation for us, so remove the old AST | ||
asset.ast = null; | ||
asset.outputCode = result.code; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const local = require('./local'); | ||
|
||
module.exports = function() { | ||
return local.a + local.b; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const util = require('./utils/util'); | ||
|
||
exports.a = 5; | ||
exports.b = util.count(4, 5); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
exports.count = function(a, b) { | ||
return a + b; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's possible to get the map without converting to JSON first. https://github.com/mishoo/UglifyJS2/blob/master/lib/sourcemap.js#L94
Might be faster - maybe you could even access the original mappings from there so you don't need to decode it.