Add a print log configuration switch to solve compilation performance problems

This commit is contained in:
mygu 2018-06-29 16:08:47 +08:00
parent 0089858eb8
commit 8300b72478
2 changed files with 17 additions and 10 deletions

View File

@ -6,6 +6,7 @@ var assign = require('object-assign');
// HTML minifier
hexo.config.neat_html = assign({
enable: true,
logger: true,
exclude: [],
ignoreCustomComments: [/^\s*more/],
removeComments: true,
@ -20,6 +21,7 @@ var assign = require('object-assign');
// Css minifier
hexo.config.neat_css = assign({
enable: true,
logger: true,
exclude: ['*.min.css']
}, hexo.config.neat_css);
@ -27,6 +29,7 @@ var assign = require('object-assign');
hexo.config.neat_js = assign({
enable: true,
mangle: true,
logger: true,
output: {},
compress: {},
exclude: ['*.min.js']

View File

@ -24,10 +24,12 @@ function logic_html(str, data) {
}
}
var log = hexo.log || console.log;
var result = Htmlminifier(str, options);
var saved = ((str.length - result.length) / str.length * 100).toFixed(2);
log.log('neat the html: %s [ %s saved]', path, saved + '%');
if (options.logger) {
var log = hexo.log || console.log;
log.log('neat the html: %s [ %s saved]', path, saved + '%');
}
var prefix = '<!-- build time:' + Date() + " -->";
var end = '<!-- rebuild by neat -->';
result = prefix + result + end;
@ -50,16 +52,18 @@ function logic_css(str, data) {
}
}
var log = hexo.log || console.log;
return new Promise(function(resolve, reject) {
new CleanCSS(options).minify(str, function(err, result) {
return new Promise(function (resolve, reject) {
new CleanCSS(options).minify(str, function (err, result) {
if (err) return reject(err);
var saved = ((str.length - result.styles.length) / str.length * 100).toFixed(2);
var prefix = '/* build time:' + Date().toLocaleString() + "*/\n";
var end = '\n/* rebuild by neat */';
var css_result = prefix + result.styles + end;
resolve(css_result);
log.log('neat the css: %s [ %s saved]', path, saved + '%');
if (options.logger) {
var log = hexo.log || console.log;
log.log('neat the css: %s [ %s saved]', path, saved + '%');
}
});
});
}
@ -80,18 +84,18 @@ function logic_js(str, data) {
}
}
var log = hexo.log || console;
var result = UglifyJS.minify(str, options);
var saved = ((str.length - result.code.length) / str.length * 100).toFixed(2);
log.log('neat the js: %s [ %s saved]', path, saved + '%');
if (options.logger) {
var log = hexo.log || console.log;
log.log('neat the js: %s [ %s saved]', path, saved + '%');
}
var prefix = '// build time:' + Date().toLocaleString() + "\n";
var end = '\n//rebuild by neat ';
var js_result = prefix + result.code + end;
return js_result;
}
module.exports = {
logic_html: logic_html,
logic_css: logic_css,