-
-
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
Change to uglify es & output uglify errors #157
Changes from 12 commits
fedbd52
3f31fc5
95ea536
f16cb57
1375ae2
b0d5348
76e243c
959d2f6
9d59def
e85f8be
a4cce81
09d19ff
a0cb51d
27975e4
a4bafd4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,37 @@ | ||
const {AST_Node, minify} = require('uglify-js'); | ||
const {toEstree} = require('babel-to-estree'); | ||
const types = require('babel-types'); | ||
const walk = require('babylon-walk'); | ||
const {minify} = require('uglify-es'); | ||
const generate = require('babel-generator').default; | ||
|
||
module.exports = async function(asset) { | ||
await asset.parseIfNeeded(); | ||
|
||
// Convert to UglifyJS AST | ||
var ast = AST_Node.from_mozilla_ast(toEstree(asset.ast, asset.contents)); | ||
var result = minify(ast, { | ||
toplevel: true | ||
}); | ||
// Convert AST into JS | ||
let code = asset.isAstDirty | ||
? generate(asset.ast).code | ||
: asset.outputCode || asset.contents; | ||
|
||
// Uglify did our code generation for us, so remove the old AST | ||
let options = { | ||
warnings: true, | ||
mangle: { | ||
toplevel: true | ||
}, | ||
compress: { | ||
drop_console: true | ||
} | ||
}; | ||
|
||
let result = minify(code, options); | ||
|
||
if (result.error) throw result.error; | ||
|
||
// Log all warnings | ||
if (result.warnings) { | ||
result.warnings.forEach(warning => { | ||
// TODO: warn this using the logger | ||
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. Would probably be better to use the logger to send warnings to the console, not really sure how to address the logger from here though 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. hmm yeah, the logger isn't really accessible from here, it lives only in the main process right now, not workers. |
||
console.log(warning); | ||
}); | ||
} | ||
|
||
// babel-generator did our code generation for us, so remove the old AST | ||
asset.ast = null; | ||
asset.outputCode = result.code; | ||
asset.isAstDirty = false; | ||
|
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.
maybe just call
asset.generate().js
here?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 extracted this bit from generate because i saw TODO: Source maps and thought this would affect performance in the future. I'll change it back to asset.generate though :)