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

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.

主站蜘蛛池模板: 广宁县| 宝坻区| 舒兰市| 鲁甸县| 江源县| 九江县| 丹江口市| 佛山市| 延川县| 闻喜县| 嫩江县| 讷河市| 阜新市| 育儿| 舟曲县| 八宿县| 兴山县| 昔阳县| 正宁县| 张家口市| 丹凤县| 定安县| 方山县| 侯马市| 崇州市| 涿州市| 垫江县| 东辽县| 东安县| 凌源市| 永嘉县| 花垣县| 靖宇县| 宿迁市| 阳朔县| 文化| 新安县| 陇西县| 日土县| 五原县| 图们市|