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

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.

主站蜘蛛池模板: 碌曲县| 民乐县| 招远市| 会同县| 永嘉县| 宝应县| 兰西县| 高邮市| 浮梁县| 玉树县| 剑川县| 盘锦市| 太白县| 慈溪市| 新竹县| SHOW| 嘉定区| 福泉市| 四川省| 威远县| 旺苍县| 资阳市| 宜阳县| 呼伦贝尔市| 罗平县| 广丰县| 同江市| 呼和浩特市| 池州市| 兴和县| 定结县| 虹口区| 宾川县| 滦南县| 临邑县| 克拉玛依市| 雅安市| 扎囊县| 遵义市| 博野县| 福鼎市|