detective-html
v0.1.0
Published
Find the dependencies of an HTML file.
Downloads
7
Readme
node-detective-html
Find the dependencies of an HTML file.
npm install detective-html
It's the HTML counterpart to detective, detective-amd, detective-es6, detective-sass.
- The AST is generated using the parse5 parser.
Usage
const fs = require("fs");
const detective = require("detective-html");
const content = fs.readFileSync("index.html", "utf8");
// list the names of the used files (ex: 'foo.css', 'foo.png', etc)
const dependencies = detective(content);
Non-standard attributes
In many cases, data-src,...
are used to lazy load images
This is possible detective outputs such non-standard attribute dependencies by adding a list of html tags and associated specific attributes. The way it is provided is similar to what webpack uses.
const options = {
sources: {
list:
[
"...",
{ tag: "img", attribute: "data-src", type: "src", },
{ tag: "img", attribute: "data-srcset", type: "srcset", },
{ tag: "source", attribute: "data-src", type: "src", },
{ tag: "source", attribute: "data-srcset", type: "srcset", },
]
}
}
const dependencies = detective(content, options);
License
MIT