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音乐插件,会无法循环播放音频。
    在博客站点根目录执行安装代码

    1. npm install hexo-neat --save

    在博客根目录下的配置文件添加代码:

    1. neat_enable: true
    2. neat_html:
    3. enable: true
    4. exclude:
    5. neat_css:
    6. enable: true
    7. exclude:
    8. - '*.min.css'
    9. neat_js:
    10. enable: true
    11. mangle: true
    12. output:
    13. compress:
    14. exclude:
    15. - '*.min.js'

    然后,可以压缩代码,部署,上传博客了。

    1. hexo cl
    2. hexo g
    3. hexo d

    补充:为了解决以上问题,在网上搜到一些解决办法,对于 matery 主题(其他主题自行解决)需要将以上默认配置修改为:

    1. neat_enable: true
    2. neat_html:
    3. enable: true
    4. exclude:
    5. - '**/*.md'
    6. neat_css:
    7. enable: true
    8. exclude:
    9. - '**/*.min.css'
    10. neat_js:
    11. enable: true
    12. mangle: true
    13. output:
    14. compress:
    15. exclude:
    16. - '**/*.min.js'
    17. - '**/**/instantpage.js'
    18. - '**/matery.js'