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 e778c55f37/index.js (L49)
This commit is contained in:
MDLeom 2024-06-05 11:08:12 +00:00
parent e99e110d39
commit e9584b2e0b
No known key found for this signature in database
GPG Key ID: 06C236E63CBC68AA
2 changed files with 5 additions and 2 deletions

View File

@ -34,6 +34,7 @@ $ npm install hexo-yam --save
``` yaml ``` yaml
minify: minify:
enable: true enable: true
previewServer: true
html: html:
css: css:
js: js:
@ -45,6 +46,7 @@ minify:
``` ```
- **enable** - Enable the plugin. Defaults to `true`. - **enable** - Enable the plugin. Defaults to `true`.
- **previewServer** - Disable the plugin when running `hexo server`. Defaults to `true`.
- **html** - See [HTML](#html) section - **html** - See [HTML](#html) section
- **css** - See [CSS](#css) section - **css** - See [CSS](#css) section
- **js** - See [JS](#js) section - **js** - See [JS](#js) section

View File

@ -2,7 +2,8 @@
'use strict' 'use strict'
hexo.config.minify = Object.assign({ hexo.config.minify = Object.assign({
enable: true enable: true,
previewServer: true
}, hexo.config.minify) }, hexo.config.minify)
hexo.config.minify.html = Object.assign({ hexo.config.minify.html = Object.assign({
@ -85,7 +86,7 @@ hexo.config.minify.json = Object.assign({
globOptions: { basename: true } globOptions: { basename: true }
}, hexo.config.minify.json) }, 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') 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:html', filter.minifyHtml, hexo.config.minify.html.priority)
hexo.extend.filter.register('after_render:css', filter.minifyCss, hexo.config.minify.css.priority) hexo.extend.filter.register('after_render:css', filter.minifyCss, hexo.config.minify.css.priority)