Registry / web-framework / rucksack-lite

rucksack-lite

JSON →
library6.0.0jsnpmunverified

rucksack-lite is a JavaScript library providing the foundational `RucksackLite` class for managing and preparing JavaScript and CSS resources. It serves as the core resource abstraction layer, differentiating it from actual bundlers, and is utilized by the more comprehensive `rucksack` bundler package. Currently at version 6.0.0, the library underwent a complete rewrite in this major release, focusing on robust handling of both local and remote resources. It defines a `RucksackResource` class internally for managing resource paths, types (JS/CSS), and generating the necessary HTML markup for inclusion. While its release cadence appears somewhat irregular, major versions signify active development with significant architectural shifts, such as licensing updates and full rewrites. Its primary differentiation lies in offering a clean, object-oriented API for resource management, abstracting away complexities of path resolution and markup generation prior to the actual bundling process.

npm install rucksack-lite
INSTALL
IMPORT
SIG · RUCKSACK-LITE
R
rucksack-lite
web-frameworkjavascriptv6.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

RucksackLite
import RucksackLite from 'rucksack-lite'
const RucksackLite = require('rucksack-lite')
RucksackLite is the default export and the main class. The package is ESM-only since v6.
RucksackResource
import { RucksackResource } from 'rucksack-lite'
import RucksackResource from 'rucksack-lite/lib/RucksackResource'
RucksackResource is a class for defining individual assets; it's documented as a constructor and likely a named export from the main module.
Dynamic Import
const { default: RucksackLite } = await import('rucksack-lite');
For environments requiring dynamic loading or specific module resolution, RucksackLite can be imported asynchronously in both ESM and CJS contexts.

This quickstart demonstrates how to instantiate `RucksackLite`, add various types of resources (remote JS by string, remote CSS explicitly via `RucksackResource`), and generate the corresponding HTML markup. It highlights the resource management capabilities without performing actual file bundling, which is the domain of the `rucksack` package.

import RucksackLite, { RucksackResource } from 'rucksack-lite'; import path from 'path'; import { fileURLToPath } from 'url'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); async function setupRucksack() { const r = new RucksackLite({ name: "my-app", bundle_dir: path.resolve(__dirname, "output"), // Ensure an absolute path for bundle_dir bundle_url: "/static", input: "main.js" // This input file isn't created in this example, but defines the primary bundle. }); // Add a remote JavaScript resource by URL string r.add("https://example.com/index.js"); // Add a remote CSS resource using the RucksackResource class for explicit typing r.add(new RucksackResource({ path: "https://example.com/styles.css", type: "css" })); // Generate the HTML markup (note: this does not perform actual bundling) const htmlMarkup = r.html(); console.log('Generated HTML Markup:\n', htmlMarkup); // The `bundle()` method primarily processes local resources for path resolution // It does NOT create actual bundled files without the full `rucksack` package and actual files. try { console.log('\nAttempting to call bundle() (no actual files created in this quickstart):'); await r.bundle(); console.log('Bundle operation completed (paths resolved, if any local resources were added).'); } catch (error) { console.warn('Bundle operation warning (expected without actual files/bundler):', error.message); } console.log('\nRefreshed Markup after potential bundle operation:'); console.log(r.html()); } setupRucksack().catch(console.error);
Debug
Known issues
breakingVersion 6.0.0 introduces a complete rewrite of the library, potentially breaking existing integrations. Key changes include a refined resource class and updated handling of local/remote resources.
fix
Review the updated API documentation, especially for resource addition (`add`) and initialization (`RucksackLite` constructor), and adapt code accordingly. The example uses ESM syntax with `import.meta.url`.
affects: >=6.0.0
breakingThe package transitioned to an ESM-only module, indicated by the use of `import` statements and `import.meta.url` in examples. CommonJS `require()` is no longer supported directly for synchronous imports.
fix
Migrate your project to use ES Modules (e.g., use `import` syntax, ensure `"type": "module"` in package.json, or use `.mjs` file extension). Alternatively, use dynamic import: `const { default: RucksackLite } = await import('rucksack-lite');` in a CommonJS context.
affects: >=6.0.0
breakingVersion 3.0.0 relicensed the project under The KINDLY License. While this might not be a direct API breaking change, it represents a significant change in usage terms and conditions which may require review by legal or compliance teams.
fix
Review The KINDLY License terms available on the project's GitHub repository to ensure compatibility with your project's licensing and usage policies.
affects: >=3.0.0
gotcha`rucksack-lite` focuses solely on resource management, path resolution, and HTML markup generation. It does not perform actual JavaScript or CSS file bundling, minification, or concatenation. For bundling, the separate `rucksack` package is required.
fix
Ensure you are using `rucksack` for actual bundling operations. `rucksack-lite` provides the resource abstraction layer. Do not expect `rucksack-lite.bundle()` to create minified or concatenated files without additional setup or the full `rucksack` package.
affects: >=1.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM
Attempting to import `rucksack-lite` using `require()` in a CommonJS module, but the package is an ES Module.
fix
Convert your module to ES Modules (e.g., use `import` syntax, ensure `"type": "module"` in package.json, or use `.mjs` file extension). Alternatively, use dynamic import: `const { default: RucksackLite } = await import('rucksack-lite');`
TypeError: RucksackLite is not a constructor
Incorrectly importing `RucksackLite` (e.g., using named import `import { RucksackLite } from 'rucksack-lite'`) when it is a default export.
fix
Use the default import syntax: `import RucksackLite from 'rucksack-lite';`
Error: bundle_dir is not defined or is not an absolute path
The `bundle_dir` option passed to `RucksackLite` constructor is either missing or provided as a relative path, which can cause issues with file operations or later bundling steps.
fix
Ensure `bundle_dir` is always an absolute path. Use Node.js built-in `path.resolve(__dirname, 'your_directory')` or similar methods to construct an absolute path.
Upgrade
Version history
6.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources