gulp压缩静态资源
hexo
Gulp基于Node.js的前端构建工具,通过Gulp的插件可以实现前端代码的编译(sass、less)、压缩、测试;图片的压缩;浏览器自动刷新;
安装依赖
在根目录下:
1 | npm install gulp --save |
创建文件gulpfile.js:
1 | // 引入需要的模块 |
运行
1 | hexo clean && hexo g && gulp default && hexo s |
完成对静态资源的压缩。
注意:
压缩静态资源时,CPU占用率会很高。
如果出现一下错误:
1 | TypeError: imagemin.jpegtran is not a function at D:\Blog\gulpfile.js:41:18 at minify-images (D:\Blog\node_modules\undertaker\lib\set-task.js:13:15) at bound (domain.js:419:14) at runBound (domain.js:432:12) at asyncRunner (D:\Blog\node_modules\async-done\index.js:55:18) at processTicksAndRejections (internal/process/task_queues.js:76:11) |
修改文件gulpfile.js
1 | imagemin.jpegtran({'progressive': true}) |