From e9584b2e0b34f7b26941aedeb96c1e2ef7643e23 Mon Sep 17 00:00:00 2001 From: MDLeom <43627182+curbengh@users.noreply.github.com> Date: Wed, 5 Jun 2024 11:08:12 +0000 Subject: [PATCH] feat: previewServer option BREAKING CHANGE plugin is now disabled by default when running `hexo server`, unless previewServer is set to false. Close #154 Inspired by https://github.com/Lete114/hexo-minify/blob/e778c55f37733680f7c727a7dd6e3507e1147c88/index.js#L49 --- README.md | 2 ++ index.js | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 73cb0f4..d1bbdf7 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ $ npm install hexo-yam --save ``` yaml minify: enable: true + previewServer: true html: css: js: @@ -45,6 +46,7 @@ minify: ``` - **enable** - Enable the plugin. Defaults to `true`. +- **previewServer** - Disable the plugin when running `hexo server`. Defaults to `true`. - **html** - See [HTML](#html) section - **css** - See [CSS](#css) section - **js** - See [JS](#js) section diff --git a/index.js b/index.js index 318533a..04570e2 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,8 @@ 'use strict' hexo.config.minify = Object.assign({ - enable: true + enable: true, + previewServer: true }, hexo.config.minify) hexo.config.minify.html = Object.assign({ @@ -85,7 +86,7 @@ hexo.config.minify.json = Object.assign({ globOptions: { basename: true } }, hexo.config.minify.json) -if (hexo.config.minify.enable === true) { +if (hexo.config.minify.enable === true && !(hexo.config.minify.previewServer === true && ['s', 'server'].includes(hexo.env.cmd))) { const filter = require('./lib/filter') hexo.extend.filter.register('after_render:html', filter.minifyHtml, hexo.config.minify.html.priority) hexo.extend.filter.register('after_render:css', filter.minifyCss, hexo.config.minify.css.priority)