mirror of
https://github.com/S2-/minifyfromhtml.git
synced 2025-08-02 20:00:05 +02:00
add exclude option
This commit is contained in:
@@ -7,7 +7,7 @@ let babel = require("babel-core");
|
|||||||
let CleanCSS = require('clean-css');
|
let CleanCSS = require('clean-css');
|
||||||
|
|
||||||
let usage = `usage:
|
let usage = `usage:
|
||||||
minifyfromhtml --js=<output js file> --css=<output css file> < <input file>
|
minifyfromhtml --js=<output js file> --css=<output css file> --exclude=<exclude files> < <input file>
|
||||||
|
|
||||||
the minification process uses babel under the hood, so you can modify
|
the minification process uses babel under the hood, so you can modify
|
||||||
the minification with a .babelrc file.
|
the minification with a .babelrc file.
|
||||||
@@ -18,11 +18,9 @@ let usage = `usage:
|
|||||||
https://github.com/jakubpawlowicz/clean-css
|
https://github.com/jakubpawlowicz/clean-css
|
||||||
|
|
||||||
example:
|
example:
|
||||||
minifyfromhtml --js=dist/mywidget.min.js --css=dist/mywidget.min.css < example/index.html
|
minifyfromhtml --js=dist/mywidget.min.js --css=dist/mywidget.min.css --exclude=js/jquery.js < example/index.html
|
||||||
`;
|
`;
|
||||||
|
|
||||||
let outputDir = argv.o;
|
|
||||||
|
|
||||||
if (argv.h) {
|
if (argv.h) {
|
||||||
console.log(usage);
|
console.log(usage);
|
||||||
return;
|
return;
|
||||||
@@ -33,6 +31,11 @@ if (!argv.js || !argv.css) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var excludeFiles = argv.exclude || [];
|
||||||
|
if (typeof(excludeFiles) === 'string') {
|
||||||
|
excludeFiles = [excludeFiles];
|
||||||
|
}
|
||||||
|
|
||||||
let readStdin = function(cb) {
|
let readStdin = function(cb) {
|
||||||
let stdin = '';
|
let stdin = '';
|
||||||
process.stdin.resume();
|
process.stdin.resume();
|
||||||
@@ -64,6 +67,15 @@ readStdin(function(html) {
|
|||||||
|
|
||||||
//process scripts
|
//process scripts
|
||||||
let scripts = getTagAttrs(dom, 'script', 'src');
|
let scripts = getTagAttrs(dom, 'script', 'src');
|
||||||
|
|
||||||
|
//remove exluded
|
||||||
|
excludeFiles.forEach(i => {
|
||||||
|
var index = scripts.indexOf(i);
|
||||||
|
if (index !== -1) {
|
||||||
|
scripts.splice(index, 1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
let processedScripts = {};
|
let processedScripts = {};
|
||||||
for (let i = 0; i < scripts.length; i++) {
|
for (let i = 0; i < scripts.length; i++) {
|
||||||
let script = scripts[i];
|
let script = scripts[i];
|
||||||
@@ -94,11 +106,25 @@ readStdin(function(html) {
|
|||||||
|
|
||||||
//process css
|
//process css
|
||||||
let styles = getTagAttrs(dom, 'link', 'href');
|
let styles = getTagAttrs(dom, 'link', 'href');
|
||||||
|
|
||||||
|
//remove exluded
|
||||||
|
excludeFiles.forEach(i => {
|
||||||
|
var index = styles.indexOf(i);
|
||||||
|
if (index !== -1) {
|
||||||
|
styles.splice(index, 1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
let processedStyles = {};
|
let processedStyles = {};
|
||||||
fs.writeFileSync(argv.css, '');
|
fs.writeFileSync(argv.css, '');
|
||||||
for (let i = 0; i < styles.length; i++) {
|
for (let i = 0; i < styles.length; i++) {
|
||||||
let style = styles[i];
|
let style = styles[i];
|
||||||
|
|
||||||
|
if (excludeFiles.indexOf(style) > -1) {
|
||||||
|
console.log(style + ' excluded');
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
let css = fs.readFileSync(style);
|
let css = fs.readFileSync(style);
|
||||||
let cleanCssOptions = '';
|
let cleanCssOptions = '';
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user