html-resources
html-resources
is a Node.js module which parses .html
files and returns resources which are included inside (such as scripts, images, stylesheets, user-defined elements). Supports both Event-based and Promise-based syntax.
Installation
$ npm install html-resources
Usage
getResources(file, options);
; const parser = ;
Promise-based syntax example
;
You can also use await
/async
syntax:
const resources = await
Event-based syntax example
const parser = ; parser;parser;parser;parser;// … parser;parser;parserstart;
Adding new resource definitions
You can specify which resources you want to parse in the resources
parameter by passing an object with two properties: tag
and attr
. By default, it will look for:
Resources.Scripts
(<script src="…"></script>
);Resources.Styles
(<link href="…" />
);Resources.Images
(<img src="…" />
);
; const parser = ; parser;parser;
Saving resources
You can use html-resources
to find, modify and re-save resources in a simple way.
parser;
Options
const parser = ;
file
HTML file to parse.
options.cwd
Current working directory. All the paths will be resolved to cwd
. By default, it's set to process.cwd()
but in most cases you want to set it manually to __dirname
or pass an absolute path to file
instead.
options.resources
An array containing all the resources definitions html-resources
should look for. By default, it is set to Resources.Scripts
, Resources.Styles
, Resources.Images
.
Tests
$ npm test