admin管理员组文章数量:1333210
I'm using Grunt hooked up with grunt-contrib-uglify
task to minify JavaScript in my app.
Upon minification, it's removing every 'use strict'
statement except the very first one, so I'm getting a huge JavaScript file with 'use strict' directive at the top.
The issue is that the global 'use strict'
directive makes the browser execute the code of every lib I'm using in the project in the "strict mode" and it's causing errors, since not every 3rd party code is written for strict mode.
Any ideas on how to solve this?
I'm using Grunt hooked up with grunt-contrib-uglify
task to minify JavaScript in my app.
Upon minification, it's removing every 'use strict'
statement except the very first one, so I'm getting a huge JavaScript file with 'use strict' directive at the top.
The issue is that the global 'use strict'
directive makes the browser execute the code of every lib I'm using in the project in the "strict mode" and it's causing errors, since not every 3rd party code is written for strict mode.
Any ideas on how to solve this?
Share Improve this question edited Dec 16, 2016 at 21:16 danwellman 9,2738 gold badges63 silver badges91 bronze badges asked Dec 19, 2013 at 14:50 Roman KolpakRoman Kolpak 2,0221 gold badge22 silver badges26 bronze badges 2- It's not easy to solve, as documented in this ment on the UglifyJS2 project page. – Matthew Bakaitis Commented Dec 19, 2013 at 15:48
- @rawry Can you try using next version github./mishoo/UglifyJS2 . Looks like the problem is solved in this new version. – Vishwanath Commented Jan 30, 2015 at 9:37
1 Answer
Reset to default 8If you wrap all your scripts with an IIFE then the grunt-contrib-uglify
won't position that statement to the stop and rather it'll leave it inside every IIFE you write.
(function() {
'use strict';
// do stuff
})();
Yes, it's more code, but if your gzipping the file it should be a non-issue. Also this will keep any variables you define outside of the global scope, leading to more performant code.
本文标签: javascriptUglifyJS 39use strict39 statementsStack Overflow
版权声明:本文标题:javascript - UglifyJS 'use strict' statements - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742277034a2445387.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论