title: 代码压缩
author: HaoQi
top: false
cover: false
toc: false
summary: hexo-neat 插件实现代码压缩
reprintPolicy: cc_by
coverlmg:
img: https://cdn.jsdelivr.net/gh/haoqiyung/image/lmages/6.jpg
date: 2022-03-29 10:15:36
categories: 插件篇
tags:
- hexo
hexo-neat 插件实现代码压缩
注意:
这个插件是有 Bug 的,压缩 md 文件会使 markdown 语法的代码块消失,会删除全角空格,并且博客使用apayer音乐插件,会无法循环播放音频。
在博客站点根目录执行安装代码:
npm install hexo-neat --save
在博客根目录下的配置文件添加代码:
neat_enable: true
neat_html:
enable: true
exclude:
neat_css:
enable: true
exclude:
- '*.min.css'
neat_js:
enable: true
mangle: true
output:
compress:
exclude:
- '*.min.js'
然后,可以压缩代码,部署,上传博客了。
hexo cl
hexo g
hexo d
补充:为了解决以上问题,在网上搜到一些解决办法,对于 matery 主题(其他主题自行解决)需要将以上默认配置修改为:
neat_enable: true
neat_html:
enable: true
exclude:
- '**/*.md'
neat_css:
enable: true
exclude:
- '**/*.min.css'
neat_js:
enable: true
mangle: true
output:
compress:
exclude:
- '**/*.min.js'
- '**/**/instantpage.js'
- '**/matery.js'