Registry / web-framework / express-simple-bundler

express-simple-bundler

JSON →
library0.2.0jsnpmunverified

express-simple-bundler is a specialized utility designed for Express.js applications, focusing on the streamlined creation of minified and cache-busted JavaScript and CSS bundles. The package, currently at version 0.2.0, indicates an early stage of development with an likely infrequent release cadence. Its core functionality involves processing specified source files, applying compression via configurable engines like UglifyJS for JavaScript and clean-css for CSS, and then outputting these bundles to a designated public directory. A key differentiator is its automatic appending of MD5 hashes to the generated filenames, which is crucial for effective cache invalidation and ensuring browsers fetch the latest asset versions upon deployment. The library integrates directly into the server-side logic of an Express application, providing bundled file paths through a global object for use in view templates. This direct integration aims to simplify asset management without requiring a separate, complex build pipeline, making it suitable for projects prioritizing simplicity within the Express ecosystem.

npm install express-simple-bundler
INSTALL
IMPORT
SIG · EXPRESS-SIMPLE-BUN
E
express-simple-bundler
web-frameworkjavascriptv0.2.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.

bundle
const bundler = require('express-simple-bundler'); bundler.bundle(bundleSettings);
import { bundle } from 'express-simple-bundler';
The package exports the bundle function directly as a CommonJS module. ESM imports are not supported.
bundle (alternative CommonJS)
const { bundle } = require('express-simple-bundler'); // This works because the default export is a function
import bundle from 'express-simple-bundler';
While technically correct due to CommonJS export behavior, the primary pattern is to call the returned function directly. ESM default imports will fail.
global bundles object
// Accessed globally after bundling // For example, in a view engine like EJS: // <link rel="stylesheet" type="text/css" src="<%= bundles.css[0] %>" />
import { bundles } from 'express-simple-bundler';
The 'bundles' object is made available globally (or via app.locals/res.locals depending on Express setup) after the bundler runs, not imported directly.

Demonstrates how to configure and execute the bundler, creating minified and hashed asset files for an Express application. Includes setup for dummy files and directories for a runnable example.

const bundler = require('express-simple-bundler'); const bundleSettings = { compress : true, // Set to true to compress and minify files bundles: [ {name : 'main.js', type:"js",output:"public/js/dist/",files:['public/js/functions.js', 'public/js/another.js']}, {name : 'main.css', type:"css",output:"public/css/dist/", files:['public/css/style.css', 'public/css/theme.css']} ], jsEngine: 'uglifyjs', // Specify a JavaScript compression engine cssEngine: 'clean-css' // Specify a CSS compression engine }; // Create dummy files for demonstration purposes const fs = require('fs'); if (!fs.existsSync('public/js')) fs.mkdirSync('public/js', { recursive: true }); if (!fs.existsSync('public/css')) fs.mkdirSync('public/css', { recursive: true }); fs.writeFileSync('public/js/functions.js', 'console.log("hello");'); fs.writeFileSync('public/js/another.js', 'function greet() { return "world"; }'); fs.writeFileSync('public/css/style.css', 'body { margin: 0; }'); fs.writeFileSync('public/css/theme.css', '.container { padding: 10px; }'); // Ensure output directories exist before bundling if (!fs.existsSync(bundleSettings.bundles[0].output)) fs.mkdirSync(bundleSettings.bundles[0].output, { recursive: true }); if (!fs.existsSync(bundleSettings.bundles[1].output)) fs.mkdirSync(bundleSettings.bundles[1].output, { recursive: true }); // Execute the bundler bundler.bundle(bundleSettings); console.log('Bundling complete. Check public/js/dist/ and public/css/dist/ for output.'); // In a real Express app, 'bundles.js' and 'bundles.css' would now be available in your views.
Debug
Known issues
gotchaThe package is in an early development stage (v0.2.0), implying the API might be unstable and subject to breaking changes in future minor versions.
fix
Review the package's GitHub repository for any new documentation or changelogs before upgrading, and test thoroughly.
affects: >=0.1.0
gotchaThe `bundle` function directly writes files to specified output directories, potentially overwriting existing files or requiring specific directory permissions.
fix
Ensure the output directories exist and are writable by the Node.js process. Back up any critical files in output directories if there's a risk of unintended overwrites.
affects: >=0.1.0
breakingThe package relies on `require()` for usage, indicating it's a CommonJS module. Attempting to use `import` syntax will result in errors.
fix
Ensure your project is configured for CommonJS, or use `require()` statements when integrating this package. If in an ESM project, consider a wrapper or dynamic import if possible.
affects: >=0.1.0
gotchaThe `jsEngine` and `cssEngine` options require the respective packages (e.g., `uglifyjs`, `clean-css`) to be installed as direct dependencies in your project, even if not explicitly listed as peer dependencies.
fix
Manually install `uglifyjs` and `clean-css` (or your chosen engines) via `npm install uglifyjs clean-css`.
affects: >=0.1.0
Errors
Common errors & fixes
Error: Cannot find module 'uglifyjs'
The configured `jsEngine` (e.g., 'uglifyjs') is not installed in your project's dependencies.
fix
Run `npm install uglifyjs` to add the required JavaScript compression engine to your project.
Error: ENOENT: no such file or directory, open 'public/js/functions.js'
One or more file paths listed in `bundleSettings.bundles[].files` are incorrect or the files do not exist at the specified location.
fix
Carefully verify all file paths in your `bundleSettings` are correct and relative to your project's root directory.
Bundled files are not appearing in the specified output directory.
The `output` directory specified in `bundleSettings.bundles[].output` might not exist or the Node.js process lacks write permissions.
fix
Ensure that the target output directories (e.g., `public/js/dist/`) exist and that your application has the necessary permissions to write files to them. You might need to create them manually or programmatically before bundling.
Bundled files are generated but not minified or compressed.
The `compress` option in `bundleSettings` is set to `false`, or the specified `jsEngine`/`cssEngine` is not working correctly.
fix
Set `compress: true` in your `bundleSettings`. Also, ensure that `uglifyjs` and `clean-css` (or your chosen engines) are correctly installed and compatible with your Node.js version.
Upgrade
Version history
0.2.0latest on npm
Audit
Dependencies
uglifyjsrequiredUsed as the default JavaScript compression engine.
clean-cssrequiredUsed as the default CSS compression engine.
Agent activity
4 hits · last 30 days
node
4
Resources
express-simple-bundler — npm install express-simple-bundler · libregistry