Bund-Cake
Bund-Cake is an early-stage JavaScript bundler and minifier specifically designed for integration with Express.js applications. It operates by taking multiple JavaScript source files and concatenating/minifying them into a single output file, which it then serves from a `/assets/bundle/` endpoint. The package, currently at version `0.0.31`, appears to be unmaintained or abandoned, with its public GitHub repository no longer accessible. This suggests no ongoing development, bug fixes, or security updates, and therefore no defined release cadence. Its primary differentiator was its direct integration within the Express application lifecycle, providing on-the-fly bundling capabilities rather than relying on a separate build step, making it suited for older, simpler Express projects that leverage server-side rendering with templating engines like EJS. Its usage of the `GLOBAL` object is indicative of older Node.js patterns.
Common errors
-
Cannot find module 'bund-cake'
cause The package has not been installed or is not resolvable in the current Node.js environment.fixRun `npm install bund-cake` in your project directory. -
TypeError: Cannot read properties of undefined (reading 'js') OR bund is not defined
cause The `bund-cake` module was not correctly initialized with your Express app, or the `GLOBAL.bund` property was not set/is being overwritten.fixEnsure `GLOBAL.bund = require('bund-cake')(app)` is called early in your application setup (e.g., `app.js`) before any views attempt to use `bund.js`. -
ReferenceError: app is not defined (when initializing bund-cake)
cause The `app` (Express application instance) variable was not in scope when `require('bund-cake')(app)` was called.fixEnsure `const app = express()` is called before `GLOBAL.bund = require('bund-cake')(app)` and `app` is properly passed.
Warnings
- breaking The `bund-cake` package is abandoned and its GitHub repository is inaccessible. There will be no further updates, bug fixes, security patches, or support for newer Node.js versions or JavaScript features. Using it in production is highly discouraged.
- gotcha Bund-Cake relies on assigning its instance to the `GLOBAL.bund` object, which is an anti-pattern in modern Node.js development. This can lead to global variable pollution and potential conflicts with other modules or environments.
- gotcha The package is tightly coupled with Express.js and older CommonJS modules. It does not support ES Modules (ESM) syntax (`import/export`) and will not work out of the box with modern JavaScript module systems.
- gotcha Bund-Cake performs runtime bundling, which can introduce performance overhead on every request in development, and potentially in production if not cached correctly. Modern build systems typically bundle at deploy-time.
Install
-
npm install bund-cake -
yarn add bund-cake -
pnpm add bund-cake
Imports
- bund
import bund from 'bund-cake'
const bund = require('bund-cake')(app); - bund.js
<%- bund.js('./path/to/script1.js', './path/to/script2.js') %>
Quickstart
const express = require('express');
const path = require('path');
const app = express();
const port = 3000;
// IMPORTANT: Bund-Cake uses GLOBAL.bund by default.
// This is an outdated and generally discouraged practice.
// In a real application, consider a wrapper or alternative.
GLOBAL.bund = require('bund-cake')(app);
// Set up EJS as the view engine
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
// Serve static files (where your original JS files live)
app.use(express.static(path.join(__dirname, 'public')));
// Create dummy JS files for bundling
const fs = require('fs');
const publicDir = path.join(__dirname, 'public', 'javascripts');
if (!fs.existsSync(publicDir)) fs.mkdirSync(publicDir, { recursive: true });
fs.writeFileSync(path.join(publicDir, 'annoying-popups.js'), 'console.log("Annoying popup script loaded!"); alert("Hello from annoying popups!");');
fs.writeFileSync(path.join(publicDir, 'one-weird-tip.js'), 'console.log("One weird tip script loaded!"); document.getElementById("tip").innerText = "Drink more water!";');
// A simple route that renders a view with bundled JS
app.get('/', (req, res) => {
res.render('index');
});
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
console.log('Open your browser to http://localhost:3000 to see the bundled JS.');
});
/*
// views/index.ejs
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bund-Cake Example</title>
</head>
<body>
<h1>Welcome to Bund-Cake Example</h1>
<p>Bundled JavaScript will be injected below:</p>
<div id="tip"></div>
<%- bund.js('./public/javascripts/annoying-popups.js', './public/javascripts/one-weird-tip.js') %>
</body>
</html>
*/