-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
JS destructuring assignment minification bug #9132
Comments
Please generate an un-minified JS file for testing. The result of:
Then post somewhere. This is probably upstream, and we need the "before" state. |
https://gist.github.com/apokaliptis/a715f5113bfba7dc4d0cd5b73b5f454f |
Here's a minimal failing example: var a = 1;
function f() {
return 1;
}
var { min, max } = Math;
function g() {
return 2;
} https://github.com/tdewolff/minify (BAD) var a=1,min,max;function f(){return 1}{min,max}=Math;function g(){return 2} https://jscompress.com (GOOD) var a=1;function f(){return 1}var{min:min,max:max}=Math;function g(){return 2} |
Upstream tdewolff/minify#445 |
It's a bug, alright. That said, I would recommend that you use the minify option in {{ $params := (dict "is_production" hugo.IsProduction ) }}
{{ $sourceMap := cond hugo.IsProduction "" "inline" }}
{{ $opts := dict "sourceMap" $sourceMap "minify" hugo.IsProduction "target" "es2018" "params" $params }}
{{ $js = $js | js.Build $opts }} |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Hi, I noticed that Hugo has a problem minifying my javascript. This is my pipeline:
It worked fine in development using
hugo server
but when I built for production usinghugo --minify
I would get an error about an unexpected colon, which means the problem is with Hugo's built-in minification functionI traced it to one of Splide's (v3.2.5) source files which I'm importing like so:
The source file that Hugo's minifier is having an issue with (after being bundled by esbuild) is
@splidejs/splide/src/js/utils/math/math/math.ts
, which contains:Apparently, after running through esbuild and Hugo's minifier it results in the following summarized code, which is invalid:
I was able to get around this by letting esbuild perform the minification instead (which I didn't know you could do at the time of discovering this error):
Which is probably the right way to minify my JS in this situation, but I decided to report this as a bug anyway because Hugo's minify tool is taking valid JS from esbuild and returning invalid JS.
What version of Hugo are you using (
hugo version
)?Does this issue reproduce with the latest release?
Yes.
The text was updated successfully, but these errors were encountered: