The base class for the Rucksack JavaScript and CSS bundler.
For bundling, use rucksack
.
# Using npm
npm install --save rucksack-lite
# Using yarn
yarn add rucksack-lite
const Rucksack = require("rucksack-lite");
const r = new Rucksack({
jsUrl: "my-bundle.js"
, cssUrl: "my-bundle.css"
});
// Local files are supposed to be added via `rucksack`
// (which implements bundling)
// Those will *not* appear in the HTML output
r.add(`${__dirname}/data/bar.css`);
r.add(`${__dirname}/data/main.css`);
// On the other side, remote scripts and styles *will* appear
// in the output, because they don't need bundling.
r.add("https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.8.0/styles/default.min.js");
r.add("https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.8.0/styles/default.min.css", false);
console.log(bundler.html())
There are few ways to get help:
- Please post questions on Stack Overflow. You can open issues with questions, as long you add a link to your Stack Overflow question.
- For bug reports and feature requests, open issues. π
Ruckasck
Creates a new instance of Ruckasck
.
- Object
opts
: The Rucksack options.
- Object The Rucksack instance.
Downloads the script from the resource file.
- String
resPath
: The path of the resource. - String
root
: The file's root path.
Downloads the JS scripts from the resource.
- String
resPath
: The path of the resource. - Boolean
inline
: Confirms if the resource needs to be downloaded or not.
Adds a new CSS path.
- String
resPath
: The CSS resource path to add. - Boolean
inline
: Whether to add the CSS content inline or not.
Bundles the JavaScript and CSS resources.
- Promise A promise object.
Creates an array of elements containing the resource type and the url.
E.g.:
[
{ type: "script", url: "https://.../myscript.js" },
...
{ type: "stylesheet", url: "https://.../mystyle.css" },
]
- Array The resources list.
Generates the HTML markup for CSS assets.
- String The HTML markup.
Generates the HTML markup for JS assets.
- String The HTML markup.
Generates the HTML for both CSS and JS assets. Optionally, a custom array can be provided.
- Array
resources
: An optional array of assets.
- String The HTML markup.
Have an idea? Found a bug? See how to contribute.
If you are using this library in one of your projects, add it in this list. β¨
rucksack