1
0
mirror of https://github.com/S2-/minifyfromhtml.git synced 2025-08-02 12:00:03 +02:00

read cleancss options from .cleancssrc file

This commit is contained in:
s2
2018-05-08 17:54:29 +02:00
parent 23254ba464
commit 39c7e6ee86
2 changed files with 25 additions and 9 deletions

View File

@@ -1,5 +1,6 @@
let argv = require('minimist')(process.argv.slice(2));
var fs = require('fs');
let fs = require('fs');
let path = require('path');
let jsdom = require('jsdom');
let JSDOM = jsdom.JSDOM;
let babel = require("babel-core");
@@ -12,8 +13,8 @@ let usage = `usage:
the minification with a .babelrc file.
https://babeljs.io/
the css minification process uses clean-css, so you can modify
the minification with
the css minification process uses clean-css. to modify the default settings,
create a file named .cleancssrc and put the json configuration in that file.
https://github.com/jakubpawlowicz/clean-css
example:
@@ -99,14 +100,21 @@ readStdin(function(html) {
let style = styles[i];
let css = fs.readFileSync(style);
let cleanCssOptions = {
level: {
1: {
specialComments: false,
rebase: false
let cleanCssOptions = '';
let readConfig = function(configfilepath) {
try {
return JSON.parse(fs.readFileSync(configfilepath + '/.cleancssrc'));
} catch (e) {
if (configfilepath != __dirname) {
configfilepath = path.resolve(path.normalize(configfilepath + '/../'));
return readConfig(configfilepath);
} else {
return {};
}
}
};
}
cleanCssOptions = readConfig(path.resolve('./'));
console.log(style + ' -> ' + argv.css);
fs.appendFileSync(argv.css, (new CleanCSS(cleanCssOptions).minify(css)).styles + '\n');