mirror of
https://github.com/S2-/minifyfromhtml.git
synced 2025-08-02 12:00:03 +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 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 with a .babelrc file.
|
||||
@@ -18,11 +18,9 @@ let usage = `usage:
|
||||
https://github.com/jakubpawlowicz/clean-css
|
||||
|
||||
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) {
|
||||
console.log(usage);
|
||||
return;
|
||||
@@ -33,6 +31,11 @@ if (!argv.js || !argv.css) {
|
||||
return;
|
||||
}
|
||||
|
||||
var excludeFiles = argv.exclude || [];
|
||||
if (typeof(excludeFiles) === 'string') {
|
||||
excludeFiles = [excludeFiles];
|
||||
}
|
||||
|
||||
let readStdin = function(cb) {
|
||||
let stdin = '';
|
||||
process.stdin.resume();
|
||||
@@ -64,6 +67,15 @@ readStdin(function(html) {
|
||||
|
||||
//process scripts
|
||||
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 = {};
|
||||
for (let i = 0; i < scripts.length; i++) {
|
||||
let script = scripts[i];
|
||||
@@ -94,11 +106,25 @@ readStdin(function(html) {
|
||||
|
||||
//process css
|
||||
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 = {};
|
||||
fs.writeFileSync(argv.css, '');
|
||||
for (let i = 0; i < styles.length; i++) {
|
||||
let style = styles[i];
|
||||
|
||||
if (excludeFiles.indexOf(style) > -1) {
|
||||
console.log(style + ' excluded');
|
||||
continue;
|
||||
}
|
||||
|
||||
let css = fs.readFileSync(style);
|
||||
let cleanCssOptions = '';
|
||||
|
||||
|
Reference in New Issue
Block a user