2016-05-26 11:09:41 +00:00
|
|
|
/* global hexo */
|
2019-05-27 01:14:04 +00:00
|
|
|
'use strict'
|
|
|
|
|
2019-12-26 11:11:36 +00:00
|
|
|
const minifyDefault = { enable: true }
|
|
|
|
const htmlDefault = {
|
2019-09-11 01:15:19 +00:00
|
|
|
enable: true,
|
2019-10-09 22:33:34 +00:00
|
|
|
priority: 10,
|
2019-12-27 22:54:09 +00:00
|
|
|
verbose: false,
|
2019-09-11 01:15:19 +00:00
|
|
|
exclude: [],
|
|
|
|
collapseBooleanAttributes: true,
|
|
|
|
collapseWhitespace: true,
|
|
|
|
// Ignore '<!-- more -->' https://hexo.io/docs/tag-plugins#Post-Excerpt
|
|
|
|
ignoreCustomComments: [/^\s*more/],
|
|
|
|
removeComments: true,
|
|
|
|
removeEmptyAttributes: true,
|
|
|
|
removeScriptTypeAttributes: true,
|
|
|
|
removeStyleLinkTypeAttributes: true,
|
|
|
|
minifyJS: true,
|
|
|
|
minifyCSS: true,
|
|
|
|
globOptions: { basename: true }
|
2019-12-26 11:11:36 +00:00
|
|
|
}
|
|
|
|
const cssDefault = {
|
2019-09-11 01:15:19 +00:00
|
|
|
enable: true,
|
2019-10-09 22:33:34 +00:00
|
|
|
priority: 10,
|
2019-12-27 22:54:09 +00:00
|
|
|
verbose: false,
|
2019-09-11 01:15:19 +00:00
|
|
|
exclude: ['*.min.css'],
|
|
|
|
level: 2,
|
|
|
|
globOptions: { basename: true }
|
2019-12-26 11:11:36 +00:00
|
|
|
}
|
|
|
|
const jsDefault = {
|
2019-09-11 01:15:19 +00:00
|
|
|
enable: true,
|
2019-10-09 22:33:34 +00:00
|
|
|
priority: 10,
|
2019-12-27 22:54:09 +00:00
|
|
|
verbose: false,
|
2019-09-11 01:15:19 +00:00
|
|
|
exclude: ['*.min.js'],
|
|
|
|
compress: {},
|
|
|
|
mangle: true,
|
|
|
|
output: {},
|
|
|
|
globOptions: { basename: true }
|
2019-12-26 11:11:36 +00:00
|
|
|
}
|
|
|
|
const svgDefault = {
|
2019-09-11 01:15:19 +00:00
|
|
|
enable: true,
|
2019-10-09 22:33:34 +00:00
|
|
|
priority: 10,
|
2019-12-27 22:54:09 +00:00
|
|
|
verbose: false,
|
2019-09-11 01:15:19 +00:00
|
|
|
include: ['*.svg', '!*.min.svg'],
|
|
|
|
plugins: [],
|
|
|
|
globOptions: { basename: true }
|
2019-12-26 11:11:36 +00:00
|
|
|
}
|
|
|
|
const gzipDefault = {
|
2019-09-11 01:15:19 +00:00
|
|
|
enable: true,
|
2019-10-09 22:33:34 +00:00
|
|
|
priority: 10,
|
2019-12-27 22:54:09 +00:00
|
|
|
verbose: false,
|
2019-09-11 01:15:19 +00:00
|
|
|
include: ['*.html', '*.css', '*.js', '*.txt', '*.ttf', '*.atom', '*.stl', '*.xml', '*.svg', '*.eot', '*.json'],
|
|
|
|
globOptions: { basename: true }
|
2019-12-26 11:11:36 +00:00
|
|
|
}
|
|
|
|
const brotliDefault = {
|
2019-09-11 01:15:19 +00:00
|
|
|
enable: true,
|
2019-10-09 22:33:34 +00:00
|
|
|
priority: 10,
|
2019-12-27 22:54:09 +00:00
|
|
|
verbose: false,
|
2019-09-11 01:15:19 +00:00
|
|
|
include: ['*.html', '*.css', '*.js', '*.txt', '*.ttf', '*.atom', '*.stl', '*.xml', '*.svg', '*.eot', '*.json'],
|
|
|
|
globOptions: { basename: true }
|
2019-12-26 11:11:36 +00:00
|
|
|
}
|
2020-01-03 00:35:25 +00:00
|
|
|
const xmlDefault = {
|
|
|
|
enable: false,
|
|
|
|
priority: 10,
|
|
|
|
verbose: false,
|
|
|
|
include: ['*.xml', '!*.min.xml'],
|
|
|
|
removeComments: true,
|
|
|
|
globOptions: { basename: true }
|
|
|
|
}
|
2020-01-03 01:16:38 +00:00
|
|
|
const jsonDefault = {
|
|
|
|
enable: false,
|
|
|
|
priority: 10,
|
|
|
|
verbose: false,
|
|
|
|
include: ['*.json', '!*.min.json'],
|
|
|
|
globOptions: { basename: true }
|
|
|
|
}
|
2019-12-26 11:11:36 +00:00
|
|
|
|
|
|
|
hexo.config.minify = Object.assign(minifyDefault, hexo.config.minify)
|
|
|
|
hexo.config.minify.html = Object.assign(htmlDefault, hexo.config.minify.html)
|
|
|
|
hexo.config.minify.css = Object.assign(cssDefault, hexo.config.minify.css)
|
|
|
|
hexo.config.minify.js = Object.assign(jsDefault, hexo.config.minify.js)
|
|
|
|
hexo.config.minify.svg = Object.assign(svgDefault, hexo.config.minify.svg)
|
|
|
|
hexo.config.minify.gzip = Object.assign(gzipDefault, hexo.config.minify.gzip)
|
|
|
|
hexo.config.minify.brotli = Object.assign(brotliDefault, hexo.config.minify.brotli)
|
2020-01-03 00:35:25 +00:00
|
|
|
hexo.config.minify.xml = Object.assign(xmlDefault, hexo.config.minify.xml)
|
2020-01-03 01:16:38 +00:00
|
|
|
hexo.config.minify.json = Object.assign(jsonDefault, hexo.config.minify.json)
|
2019-09-11 01:15:19 +00:00
|
|
|
|
|
|
|
if (hexo.config.minify.enable === true) {
|
2018-10-26 04:57:23 +00:00
|
|
|
const filter = require('./lib/filter')
|
2019-10-09 22:33:34 +00:00
|
|
|
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:js', filter.minifyJs, hexo.config.minify.js.priority)
|
|
|
|
hexo.extend.filter.register('after_generate', filter.minifySvg, hexo.config.minify.svg.priority)
|
|
|
|
hexo.extend.filter.register('after_generate', filter.gzipFn, hexo.config.minify.gzip.priority)
|
|
|
|
hexo.extend.filter.register('after_generate', filter.brotliFn, hexo.config.minify.brotli.priority)
|
2020-01-03 00:35:25 +00:00
|
|
|
hexo.extend.filter.register('after_generate', filter.minifyXml, hexo.config.minify.xml.priority)
|
2020-01-03 01:16:38 +00:00
|
|
|
hexo.extend.filter.register('after_generate', filter.minifyJson, hexo.config.minify.json.priority)
|
2018-09-29 05:38:45 +00:00
|
|
|
}
|
2019-12-26 11:11:36 +00:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
minifyDefault,
|
|
|
|
htmlDefault,
|
|
|
|
cssDefault,
|
|
|
|
jsDefault,
|
|
|
|
svgDefault,
|
|
|
|
gzipDefault,
|
2020-01-03 00:35:25 +00:00
|
|
|
brotliDefault,
|
2020-01-03 01:16:38 +00:00
|
|
|
xmlDefault,
|
|
|
|
jsonDefault
|
2019-12-26 11:11:36 +00:00
|
|
|
}
|