官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 浦东新区| 新安县| 涟水县| 错那县| 霍城县| 唐海县| 时尚| 博客| 翁源县| 黄山市| 旬阳县| 德安县| 建德市| 北宁市| 大埔县| 福安市| 北京市| 万州区| 潜江市| 徐汇区| 杂多县| 玉环县| 即墨市| 包头市| 治县。| 曲水县| 深圳市| 承德市| 滨海县| 遂平县| 安化县| 泽普县| 兴隆县| 山西省| 黑龙江省| 西安市| 巴青县| 富顺县| 通山县| 上林县| 稻城县|