Registry / devops / rucksack

rucksack

JSON →
library0.1.0jsnpmunverified

Rucksack is a JavaScript and CSS bundler built atop Vite, designed to simplify the asset bundling process for modern web applications. Currently stable at version 7.1.1, the package receives relatively frequent minor and patch updates, often aligning with new Vite releases or internal dependency bumps. Major versions, such as the transition from 6.x to 7.x, introduce significant dependency upgrades and can include breaking changes like increased Node.js version requirements. Rucksack differentiates itself by providing a streamlined, opinionated API over raw Vite configurations, allowing developers to quickly set up bundling for local and remote JavaScript and CSS assets, and automatically generate corresponding HTML markup. It aims to abstract away much of Vite's complexity while still allowing access to the underlying Vite configuration for advanced customization.

npm install rucksack
INSTALL
IMPORT
SIG · RUCKSACK
R
rucksack
devopsjavascriptv0.1.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
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 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

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

Rucksack
✓ import Rucksack from 'rucksack'
✗ const Rucksack = require('rucksack')
Rucksack is an ESM-first package; CommonJS `require()` is not supported. It exports a default class.
Rucksack (named import)
✓ import Rucksack from 'rucksack'
✗ import { Rucksack } from 'rucksack'
The primary `Rucksack` class is exported as the default, not a named export. Attempting a named import will result in an undefined or an error.

Demonstrates how to create a Rucksack bundler instance, configure input/output paths, add remote resources, and trigger the bundling process to generate HTML markup. Includes setup for dummy files to make the example runnable.

import Rucksack from "rucksack" import { fileURLToPath } from 'url'; import path from 'path'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); async function runBundler() { // Create a new bundler instance let bundler = new Rucksack({ name: "my-app", bundle_dir: `${__dirname}/output`, bundle_url: "/static", input: `${__dirname}/js-and-css-with-assets/main.js`, // Assuming this file exists for demo production: true, watch: false, config: async (existingConfig) => { // Example: Force ES module output for Rollup existingConfig.build.rollupOptions = existingConfig.build.rollupOptions || {}; existingConfig.build.rollupOptions.output = existingConfig.build.rollupOptions.output || {}; existingConfig.build.rollupOptions.output.format = "es"; return existingConfig; } }) // Add a remote URL as a resource (e.g., jQuery CDN) bundler.add("https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js") // Execute the bundling process await bundler.bundle(); console.log("Bundling complete. Generated HTML markup:"); console.log(bundler.html()); // Expected output (paths/sizes may vary): // <script src="/static/my-app.js"></script> // <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js"></script> // <link rel="stylesheet" href="/static/my-app.css" /> } // Create dummy input files for the example to run import { promises as fs } from 'fs'; import { dirname } from 'path'; import { fileURLToPath } from 'url'; const exampleDir = path.join(__dirname, 'js-and-css-with-assets'); const outputFile = path.join(__dirname, 'output'); async function setupDummyFiles() { await fs.mkdir(exampleDir, { recursive: true }); await fs.mkdir(outputFile, { recursive: true }); await fs.writeFile(path.join(exampleDir, 'main.js'), 'import "./style.css"; console.log("Hello from main.js");'); await fs.writeFile(path.join(exampleDir, 'style.css'), 'body { background-color: #f0f0f0; }'); } setupDummyFiles().then(runBundler).catch(console.error);
Debug
Known issues
breakingVersion 5.0.0 and subsequent major versions of Rucksack require Node.js 14 or higher due to updated dependencies. Running with older Node.js versions will lead to errors.
fix
Upgrade your Node.js environment to version 14.x or newer. It is recommended to use the latest LTS version of Node.js.
affects: >=5.0.0
gotchaRucksack is built on Vite, and while it provides a simplified API, advanced customization often requires modifying the underlying Vite configuration through the `options.config` function. This necessitates familiarity with Vite's own configuration structure, which can change between Vite's major versions.
fix
Refer to the official Vite documentation for the specific version of Vite that Rucksack is using (check `rucksack/package.json` for `vite` dependency) when making custom configuration changes.
affects: >=5.0.0
breakingAs of major versions (e.g., 6.0.0 to 7.0.0), Rucksack updates its internal Vite dependency. Breaking changes in Vite itself can indirectly affect Rucksack users, especially those using the `config` option to modify Vite's internal configuration.
fix
Review release notes for Rucksack and the underlying Vite version for any breaking changes related to configuration options or API behavior when upgrading major versions of Rucksack.
affects: >=6.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module ... not supported.
Attempting to use `require()` to import `rucksack`, which is an ECMAScript Module (ESM) package.
fix
Change `const Rucksack = require('rucksack')` to `import Rucksack from 'rucksack'` and ensure your environment supports ESM (e.g., run with `node --experimental-modules your-file.js` or ensure `type: module` in `package.json`).
TypeError: Rucksack is not a constructor
The `Rucksack` class is the default export, but it's being imported incorrectly (e.g., as a named import or the `new` keyword is missing).
fix
Ensure you are using the correct default import syntax: `import Rucksack from 'rucksack';` and then instantiate it with `new Rucksack(...)`.
Vite error: Cannot find module '...' or path '...' is not found.
The `input` path for the bundler is incorrect, or a module imported within your input files cannot be resolved by Vite.
fix
Verify that the `input` path in your Rucksack options is correct and absolute. If it's an internal module, ensure it's resolvable relative to your input file or configure `aliases` in the Rucksack options to map module paths.
Upgrade
Version history
0.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
rucksack — npm install rucksack · libregistry