mirror of
https://github.com/S2-/minifyfromhtml.git
synced 2025-08-02 20:00:05 +02:00
read cleancss options from .cleancssrc file
This commit is contained in:
8
.cleancssrc
Normal file
8
.cleancssrc
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"level": {
|
||||||
|
"1": {
|
||||||
|
"specialComments": false,
|
||||||
|
"rebase": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -1,5 +1,6 @@
|
|||||||
let argv = require('minimist')(process.argv.slice(2));
|
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 = require('jsdom');
|
||||||
let JSDOM = jsdom.JSDOM;
|
let JSDOM = jsdom.JSDOM;
|
||||||
let babel = require("babel-core");
|
let babel = require("babel-core");
|
||||||
@@ -12,8 +13,8 @@ let usage = `usage:
|
|||||||
the minification with a .babelrc file.
|
the minification with a .babelrc file.
|
||||||
https://babeljs.io/
|
https://babeljs.io/
|
||||||
|
|
||||||
the css minification process uses clean-css, so you can modify
|
the css minification process uses clean-css. to modify the default settings,
|
||||||
the minification with
|
create a file named .cleancssrc and put the json configuration in that file.
|
||||||
https://github.com/jakubpawlowicz/clean-css
|
https://github.com/jakubpawlowicz/clean-css
|
||||||
|
|
||||||
example:
|
example:
|
||||||
@@ -99,14 +100,21 @@ readStdin(function(html) {
|
|||||||
let style = styles[i];
|
let style = styles[i];
|
||||||
|
|
||||||
let css = fs.readFileSync(style);
|
let css = fs.readFileSync(style);
|
||||||
let cleanCssOptions = {
|
let cleanCssOptions = '';
|
||||||
level: {
|
|
||||||
1: {
|
let readConfig = function(configfilepath) {
|
||||||
specialComments: false,
|
try {
|
||||||
rebase: false
|
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);
|
console.log(style + ' -> ' + argv.css);
|
||||||
fs.appendFileSync(argv.css, (new CleanCSS(cleanCssOptions).minify(css)).styles + '\n');
|
fs.appendFileSync(argv.css, (new CleanCSS(cleanCssOptions).minify(css)).styles + '\n');
|
||||||
|
Reference in New Issue
Block a user