{"id":15612,"library":"express-simple-bundler","title":"Express Simple Bundler","description":"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.","status":"maintenance","version":"0.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/CraigLager/express-simple-bundler","tags":["javascript","bundle","bundler","bundling","css","express"],"install":[{"cmd":"npm install express-simple-bundler","lang":"bash","label":"npm"},{"cmd":"yarn add express-simple-bundler","lang":"bash","label":"yarn"},{"cmd":"pnpm add express-simple-bundler","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used as the default JavaScript compression engine.","package":"uglifyjs","optional":false},{"reason":"Used as the default CSS compression engine.","package":"clean-css","optional":false}],"imports":[{"note":"The package exports the bundle function directly as a CommonJS module. ESM imports are not supported.","wrong":"import { bundle } from 'express-simple-bundler';","symbol":"bundle","correct":"const bundler = require('express-simple-bundler');\nbundler.bundle(bundleSettings);"},{"note":"While technically correct due to CommonJS export behavior, the primary pattern is to call the returned function directly. ESM default imports will fail.","wrong":"import bundle from 'express-simple-bundler';","symbol":"bundle (alternative CommonJS)","correct":"const { bundle } = require('express-simple-bundler'); // This works because the default export is a function"},{"note":"The 'bundles' object is made available globally (or via app.locals/res.locals depending on Express setup) after the bundler runs, not imported directly.","wrong":"import { bundles } from 'express-simple-bundler';","symbol":"global bundles object","correct":"// Accessed globally after bundling\n// For example, in a view engine like EJS:\n// <link rel=\"stylesheet\" type=\"text/css\" src=\"<%= bundles.css[0] %>\" />"}],"quickstart":{"code":"const bundler = require('express-simple-bundler');\n\nconst bundleSettings = {\n  compress : true, // Set to true to compress and minify files\n  bundles: [\n     {name : 'main.js', type:\"js\",output:\"public/js/dist/\",files:['public/js/functions.js', 'public/js/another.js']},\n     {name : 'main.css', type:\"css\",output:\"public/css/dist/\", files:['public/css/style.css', 'public/css/theme.css']}\n  ],\n  jsEngine: 'uglifyjs', // Specify a JavaScript compression engine\n  cssEngine: 'clean-css' // Specify a CSS compression engine\n};\n\n// Create dummy files for demonstration purposes\nconst fs = require('fs');\nif (!fs.existsSync('public/js')) fs.mkdirSync('public/js', { recursive: true });\nif (!fs.existsSync('public/css')) fs.mkdirSync('public/css', { recursive: true });\nfs.writeFileSync('public/js/functions.js', 'console.log(\"hello\");');\nfs.writeFileSync('public/js/another.js', 'function greet() { return \"world\"; }');\nfs.writeFileSync('public/css/style.css', 'body { margin: 0; }');\nfs.writeFileSync('public/css/theme.css', '.container { padding: 10px; }');\n\n// Ensure output directories exist before bundling\nif (!fs.existsSync(bundleSettings.bundles[0].output)) fs.mkdirSync(bundleSettings.bundles[0].output, { recursive: true });\nif (!fs.existsSync(bundleSettings.bundles[1].output)) fs.mkdirSync(bundleSettings.bundles[1].output, { recursive: true });\n\n// Execute the bundler\nbundler.bundle(bundleSettings);\n\nconsole.log('Bundling complete. Check public/js/dist/ and public/css/dist/ for output.');\n// In a real Express app, 'bundles.js' and 'bundles.css' would now be available in your views.","lang":"javascript","description":"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."},"warnings":[{"fix":"Review the package's GitHub repository for any new documentation or changelogs before upgrading, and test thoroughly.","message":"The 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.","severity":"gotcha","affected_versions":">=0.1.0"},{"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.","message":"The `bundle` function directly writes files to specified output directories, potentially overwriting existing files or requiring specific directory permissions.","severity":"gotcha","affected_versions":">=0.1.0"},{"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.","message":"The package relies on `require()` for usage, indicating it's a CommonJS module. Attempting to use `import` syntax will result in errors.","severity":"breaking","affected_versions":">=0.1.0"},{"fix":"Manually install `uglifyjs` and `clean-css` (or your chosen engines) via `npm install uglifyjs clean-css`.","message":"The `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.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Run `npm install uglifyjs` to add the required JavaScript compression engine to your project.","cause":"The configured `jsEngine` (e.g., 'uglifyjs') is not installed in your project's dependencies.","error":"Error: Cannot find module 'uglifyjs'"},{"fix":"Carefully verify all file paths in your `bundleSettings` are correct and relative to your project's root directory.","cause":"One or more file paths listed in `bundleSettings.bundles[].files` are incorrect or the files do not exist at the specified location.","error":"Error: ENOENT: no such file or directory, open 'public/js/functions.js'"},{"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.","cause":"The `output` directory specified in `bundleSettings.bundles[].output` might not exist or the Node.js process lacks write permissions.","error":"Bundled files are not appearing in the specified output directory."},{"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.","cause":"The `compress` option in `bundleSettings` is set to `false`, or the specified `jsEngine`/`cssEngine` is not working correctly.","error":"Bundled files are generated but not minified or compressed."}],"ecosystem":"npm"}