mirror of
https://github.com/S2-/minifyfromhtml.git
synced 2025-08-03 20:30:04 +02:00
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
439b2733a6 | |||
d989c9f491 | |||
e659f2acb8 | |||
16d5a653c2 |
3
example/css/mywidget-alt.css
Normal file
3
example/css/mywidget-alt.css
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#mywidget {
|
||||||
|
border: 2px solid blue;
|
||||||
|
}
|
1
example/dist/dist.css
vendored
Normal file
1
example/dist/dist.css
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#mywidget{border:2px solid red}
|
2
example/dist/dist.js
vendored
Normal file
2
example/dist/dist.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
<!-- some css -->
|
<!-- some css -->
|
||||||
<link rel="stylesheet" type="text/css" href="css/mywidget.css" />
|
<link rel="stylesheet" type="text/css" href="css/mywidget.css" />
|
||||||
|
<link rel="alternate stylesheet" type="text/css" href="css/mywidget.css" />
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
|
@@ -45,19 +45,22 @@ let readStdin = function(cb) {
|
|||||||
|
|
||||||
readStdin(function(html) {
|
readStdin(function(html) {
|
||||||
let dom = new JSDOM(html);
|
let dom = new JSDOM(html);
|
||||||
let getTagAttrs = function(dom, tag, attr) {
|
let getTagAttrs = function(dom, tag, attr, filter) {
|
||||||
let scripts = [];
|
let elements = [];
|
||||||
|
|
||||||
let document = dom.window.document;
|
let document = dom.window.document;
|
||||||
let scriptTags = document.getElementsByTagName(tag);
|
let elementTags = document.getElementsByTagName(tag);
|
||||||
let i = scriptTags.length;
|
let i = elementTags.length;
|
||||||
for (let i = 0; i < scriptTags.length; i++) {
|
for (let i = 0; i < elementTags.length; i++) {
|
||||||
let src = scriptTags[i].getAttribute(attr);
|
if (!filter ||
|
||||||
if (src) {
|
(filter && elementTags[i].getAttribute(Object.keys(filter)[0]) === filter[Object.keys(filter)[0]])) {
|
||||||
scripts.push(src);
|
let src = elementTags[i].getAttribute(attr);
|
||||||
|
if (src) {
|
||||||
|
elements.push(src);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return scripts;
|
return elements;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -101,6 +104,6 @@ readStdin(function(html) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (argv.css) {
|
if (argv.css) {
|
||||||
processThings(getTagAttrs(dom, 'link', 'href'), argv.css);
|
processThings(getTagAttrs(dom, 'link', 'href', {rel: 'stylesheet'}), argv.css);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
2
package-lock.json
generated
2
package-lock.json
generated
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "minifyfromhtml",
|
"name": "minifyfromhtml",
|
||||||
"version": "1.1.5",
|
"version": "1.1.7",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "minifyfromhtml",
|
"name": "minifyfromhtml",
|
||||||
"version": "1.1.5",
|
"version": "1.1.7",
|
||||||
"description": "minify scripts and css starting from an html file",
|
"description": "minify scripts and css starting from an html file",
|
||||||
"main": "minifyfromhtml.js",
|
"main": "minifyfromhtml.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
Reference in New Issue
Block a user