"Minify JavaScript" / UglifyJS fails without reporting error
See original GitHub issueI’m running html-minifier 3.5.14 locally but also tried the current online version http://kangax.github.io/html-minifier/ with my code, which just does not seem to minify the javascript.
I’ve narrowed down the cause to a const
declaration:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>title</title>
<style>
html,
body {
margin: 0;
padding: 0;
}
</style>
<script>
document.addEventListener("DOMContentLoaded", function() {
const fail = [{n:"object"},];
}); //
</script>
</head>
<body>
Hello world!
</body>
</html>
results in
<!doctype html><html lang=en><meta charset=UTF-8><title>title</title><style>body,html{margin:0;padding:0}</style><script>document.addEventListener("DOMContentLoaded", function() {
const fail = [{n:"object"},];
}); //</script>Hello world!
It works when I change it to a plain old var
.
There’s a note on SO: https://stackoverflow.com/a/47440295
UglifyJS does not support es6. const is an es6 declaration, so it throws an error. What is weird is that the package you use does not transpile its files to es5 to be used anywhere. If you want to still use UglifyJS (to re-use the configuration for example) use the ES6+ compatible version, uglify-es.
However, I don’t get an error with my local html-minfier either.
It would be nice if the user would get to see the underlying error message.
It also can't handle default function parameters, `let`, `=>`, etc. . There's a demo at http://lisperator.net/uglifyjs/ which throws errors.
Issue Analytics
- State:
- Created 5 years ago
- Comments:10
Top GitHub Comments
@janusz-bb, here’s a snippet of a module I wrote for one of my projects. The code belongs to a helper function that minifies HTML content (via html-minifier) rendered by Pug on a server application using Express.
Notice how I plug in Terser in the
minifyJS
field of theminify
method. That’s how I use Terser with html-minifier. 😃Right, again, that was acknowledged in the original issue report:
Silently failing instead of having an error or warning is egregious. I’d like to know what the use case is for a tool to silently fail when passed unsupported input?
Precisely we are petitioning for the design to change which would make the tool more reliable & save downstream users lots of wasted time & woes. Is there an actual objection to changing the design? It doesn’t seem to make much sense to expend time debating whether this is a feature request vs a bug, if that’s your intention, we’re just expressing our opinion that the current behavior is not very useful & that changing the behavior would be more useful to us.
People will end up with seemingly random unminified output with no idea why, spend lots of time hunting down why, then will end up here & expend your time posting issues… If the tool outputted a warning then at least users would be cognizant of the implications of adding es6, and would be able to make a deliberate decision to either not use es6 / disable minification intentionally.
I would like to know if you are objecting to making a change here, and the reason why? Simply replying with facts that were already stated in the original issue report are not particularly helpful. I think it would be more helpful to outright say that you’re not supporting the use case (and if so why), or acknowledge that the current workflow can be improved so that someone can start on a PR? Instead it seems to me like we may be spinning our wheels here without any resolution one way or the other, and I have to wonder to what end.
This is a great tool & I while I cannot speak for others, I feel the intention of the community is to make it even greater, not debate semantics.