前面介绍了一种压缩hexo页面的方法,通过gulp配合它的插件来实现,我们还可以通过hexo插件(Hexo-all-minifier)来实现。
通过插件的方式会在generate
时对html,css,js,图片等进行压缩,编译的时间会比较长,建议使用[gulp方式][gulp-minifier]实现。
[gulp-minifier]: hexo-minify.html “Hexo优化方案 gulp插件静态资源压缩”
安装
npm install hexo-all-minifier --save |
Mac用户还需要执行下面的命令
brew install libtool automake autoconf nasm |
配置
在hexo的配置文件_config.yml
中加入下面的配置参数:
html_minifier: |
enable -开始插件,默认为true
exclude: 设置不需要压缩的文件
css_minifier: |
enable -开始插件,默认为true
exclude: 设置不需要压缩的文件
js_minifier:
enable: true
mangle: true
output:
compress:
exclude:
- '*.min.js
enable -开始插件,默认为true
exclude: 设置不需要压缩的文件
mangle: 破坏文件名称
output: 输出选项
compress: 压缩选项
exclude: 设置不需要压缩的文件
image_minifier:
enable: true
interlaced: false
multipass: false
optimizationLevel: 2
pngquant: false
progressive: false
enable -开启插件,默认为true
interlaced - 默认为 false。
multipass - 多次优化svg图片直至其完全优化 默认 false。
optimizationLevel - 选择 0 到 7 的优化级别。 默认为 2。
pngquant - 开启 imagemin-pngquant
插件。 默认为 false。
progressive - 以低失真模式压缩。 默认为 false。
实际测试用图片压缩报错,暂时关闭图片压缩功能。
END