- Mastering PhoneGap Mobile Application Development
- Kerri Shotts
- 170字
- 2021-07-16 13:03:53
Uglifying your code
Code uglification or minification sounds a bit painful, but it's a really simple step we can add to our workflow. It will reduce the size of our applications when we build in release mode. Uglification also tends to obfuscate our code a little bit, but don't rely on this for any security—obfuscation can be easily undone.
To add code uglification, add the following line of code to the top of our gulp/tasks/copy-code.js
file:
var …, uglify = require("gulp-uglify");
We can then uglify our code by adding the following code immediately after .pipe(concat("app.js"))
in our projectTasks.copyCode
method:
.pipe(isRelease ? uglify({preserveComments: "some"}) : gutil.noop())
Notice that we added the uglify
method only when the build mode was release
. This means that we'll only trigger it if we execute gulp build --mode release
.
You can, of course, specify additional options. If you want to see all the documentation, visit https://github.com/mishoo/UglifyJS2/. Our options include certain comments (which most likely are license-related) while stripping out all the other comments.
- JavaScript從入門(mén)到精通(微視頻精編版)
- UML和模式應(yīng)用(原書(shū)第3版)
- Java加密與解密的藝術(shù)
- Python Data Analysis(Second Edition)
- Unity 2D Game Development Cookbook
- Python之光:Python編程入門(mén)與實(shí)戰(zhàn)
- UI設(shè)計(jì)全書(shū)(全彩)
- Scratch趣味編程:陪孩子像搭積木一樣學(xué)編程
- 深入淺出Go語(yǔ)言編程
- Apache Camel Developer's Cookbook
- Python語(yǔ)言科研繪圖與學(xué)術(shù)圖表繪制從入門(mén)到精通
- 網(wǎng)絡(luò)數(shù)據(jù)采集技術(shù):Java網(wǎng)絡(luò)爬蟲(chóng)實(shí)戰(zhàn)
- Python機(jī)器學(xué)習(xí)開(kāi)發(fā)實(shí)戰(zhàn)
- IBM RUP參考與認(rèn)證指南
- 基于JavaScript的WebGIS開(kāi)發(fā)