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-liteimport RucksackLite from "../lib/index.js";
const __dirname = new URL(".", import.meta.url).pathname;
const r = new RucksackLite({
name: "my-app",
bundle_dir: `${__dirname}/output`,
bundle_url: "/static",
input: "main.js"
});
r.add("https://example.com/index.js");
r.add("https://example.com/styles.css");
console.log(r.html())
// <script src="/static/my-app.js"></script>
// <script src="https://example.com/index.js"></script>
// <link rel="stylesheet" href="/static/my-app.css" />
// <link rel="stylesheet" href="https://example.com/styles.css" />Creates a new instance of RuckasckLite.
- Object
options: The options object:name(String): The bundle name.bundle_dir(String): The bundle directory.bundle_url(String): The bundle URL.input(String): The input file.
- Object The Rucksack instance containing:
options(Object): The options object.bundle_paths(Object): The bundle paths:js(String): The JS bundle path.css(String): The CSS bundle path.
bundle_urls(Object): The bundle URLs:js(String): The JS bundle URL.css(String): The CSS bundle URL.
local(Object): The local resources collection.js(Array): The JS resources.css(Array): The CSS resources.
remote(Object): The remote resources collection.js(Array): The JS resources.css(Array): The CSS resources.
markup(Object): The cached HTML markup:js(String): The JS HTML markup.css(String): The CSS HTML markup.all(String): The combined HTML markup.
Adds the resource to the list.
- String|Array|RucksackResource
resource: The resource path or object or an array of resources.
- RucksackResource The resource object.
Bundles the JavaScript and CSS resources.
- Promise A promise object.
Creates an array of resource objects. Optionally, a type can be provided to filter the results.
E.g.:
[
{RucksackResource},
{RucksackResource},
...
]- 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 array of resources.
- String The HTML markup.
Refreshes the cached HTML markup.
Creates a new instance of RucksackResource.
- String|Object
resource: The resource path or object containing:path(String): The resource path.type(String): The resource type. Eitherjsorcss.root(String): The root path.
- RucksackResource The resource instance containing:
path(String): The resource path.root(String): The root path.type(String): The resource type. Eitherjsorcss.source_type(String): The source type. Eitherlocalorremote.uri(String): The resource URI (full path).
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. π
Have an idea? Found a bug? See how to contribute.