-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Minification not working #2055
Comments
Your example seems to be working as expected: $ cat test.js
window.fbAsyncInit = function() {
FB.init({
version: 'v2.9'
})
}
$ uglifyjs test.js -mc
window.fbAsyncInit=function(){FB.init({version:"v2.9"})}; |
Even if I try to use <html>
<head>
<script>
window.fbAsyncInit = function() {
FB.init({
version: 'v2.9'
})
}
</script>
</head>
<body></body>
</html> using default options: <script>window.fbAsyncInit=function(){FB.init({version:"v2.9"})}</script> |
I see. I have also tried HTMLMinifier's online version and it worked for me as well. I have tried this in my example project and it works, even if I upgrade it to HTMLMinifier 3.5.2. So unfortunately I can't reproduce this issue in that project. However in my private project, which is based on the mentioned example project, it doesn't work. I investigated the issue and it was definitely intruduced when the project's HTMLMinifier dependency was updated to version 3.5.2 from version 3.4.4 (the |
I don't have an account on GitLab unfortunately, nor am I too familiar to Do you use |
I'd also look at the equivalent of |
I see. You can register here if you wish (for free). It is really similar to GitHub. Basically I am using Yes, I am using it directly as you can see here. Thank you for your suggestion! I have 1 copy of
Somehow I have fewer
|
Does your codebase run to some extent without |
Yes, it does, both in production and development mode. I have removed The build process is handled by Razzle which is using |
I think you need to remove that copy of Other than that, I'm out of ideas for now - will post if something comes to mind. Meanwhile if you can narrow it down to a test case that would be helpful as well. |
I see. Unfortunately this doesn't helps either. I have removed them before actually starting the server after the build process. The only thing I have noticed is that |
Yes, even I guess you might have done it already - have you tried a clean
|
I see, I also thought it is fine. Yes, I have. It seems you know me well. :) Now I have tried it with using What do you think, should I raise an issue at Razzle? |
Worth a shot - I'm out of ideas at the moment. 😅 |
Finally I have found what causing this. So the issue became reproducible. This issue happens, when you use HTMLMinifier 3.5.0+ and you add the following code or similiar codes to this line: Array.prototype.contains = function(element) {
return !!~this.indexOf(element)
} Plus you add a code like this to the server somewhere here: <script>
window.fbAsyncInit = function() {
FB.init({
version: 'v2.9'
})
}
</script> So now this issue can be reproduced with my Razzle Material UI Styled Example repository. Note: HTML5Minifier's version should be changed as well here. |
Thanks for your perseverance - I shall look into your example above and investigate right away 😉 |
You are welcome! All right, thank you! |
So preliminary results show that by overriding --- a/package.json
+++ b/package.json
@@ -6,7 +6,7 @@
, "dependencies": {
"express": "4.x"
, "compression": "1.x"
- , "html-minifier": "3.4.4"
+ , "html-minifier": "3.5.2"
, "react": "15.x"
, "react-dom": "15.x" --- a/src/application/Main.js
+++ b/src/application/Main.js
@@ -21,7 +21,13 @@ const Div = styled.div`
text-align: center;
padding-top: 200px;
`
-
+Array.prototype.contains = function(element) {
+ try {
+ return !!~this.indexOf(element)
+ } catch (e) {
+ console.error(e.stack)
+ throw e
+ }
+}
class Main extends Component {
constructor(properties, context) {
super(properties, context) --- a/src/server.js
+++ b/src/server.js
@@ -37,8 +37,13 @@ server
` + (assets.client.css ?
'<link rel="stylesheet" href="' + assets.client.css + '">' : ''
) + css + `
-
- <script async src="` + assets.client.js + `"></script>
+<script>
+ window.fbAsyncInit = function() {
+ FB.init({
+ version: 'v2.9'
+ })
+ }
+</script>
</head>
<body>
<div id="root">` + html + `</div> This will give, after
Technically it is out of scope for |
I see. I don't overwrite I have tried your example and you can name the function whatever you wish and the same error will be displayed. For example: |
Indeed - and I think I know why now: Basically it's down to this: $ node
> for (var name in ['a','b']) console.log(name);
0
1
> Array.prototype.contains = 'foo';
> for (var name in ['a','b']) console.log(name);
0
1
contains So this is a bug with |
kangax/html-minifier#823
ES5 in and out put example:
Uglify version: 3.0.x
minify()
options used: The one's that HTMLMinifier usesThe text was updated successfully, but these errors were encountered: