{"id":15559,"library":"bundlex","title":"Bundlex JavaScript Bundler","description":"Bundlex is a JavaScript bundler designed for high performance and scalability, offering in-memory bundling of JavaScript, TypeScript, and JSON files. Currently at stable version 3.0.4, it differentiates itself by its focus on speed and the ability to create highly customizable bundling workflows through its `createBundler` API. While a specific release cadence isn't published, the frequent updates to similar tools suggest an active development cycle. Beyond basic bundling, Bundlex includes a built-in listener for file change events, enabling efficient watch-mode development. Its architecture supports custom bundler implementations by allowing users to define their own info extractor and bundler functions, providing flexibility for niche requirements.","status":"active","version":"3.0.4","language":"javascript","source_language":"en","source_url":"https://github.com/alisa4y/js-bundler","tags":["javascript","bundler","json","typescript","quick","fast","rapid","watchable"],"install":[{"cmd":"npm install bundlex","lang":"bash","label":"npm"},{"cmd":"yarn add bundlex","lang":"bash","label":"yarn"},{"cmd":"pnpm add bundlex","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The primary function for bundling files. Bundlex is ESM-first; CommonJS require() may not be supported directly.","wrong":"const jsBundler = require('bundlex').jsBundler;","symbol":"jsBundler","correct":"import { jsBundler } from 'bundlex';"},{"note":"Used to create custom bundler instances with specific info extractor and bundler logic.","symbol":"createBundler","correct":"import { createBundler } from 'bundlex';"},{"note":"TypeScript types for defining custom bundler logic. Essential for strong typing when using `createBundler`.","symbol":"InfoExtractor, Bundler","correct":"import type { InfoExtractor, Bundler } from 'bundlex';"}],"quickstart":{"code":"import { jsBundler } from 'bundlex';\nimport path from 'path';\nimport fs from 'fs/promises';\n\n// Define temporary files for the demo\nconst entryFile = path.resolve('./temp-entry.ts');\nconst depFile = path.resolve('./temp-dependency.ts');\n\nasync function runBundlexQuickstart() {\n  // Create dummy files for bundling\n  await fs.writeFile(depFile, `export const message = \"Hello from dependency!\";`);\n  await fs.writeFile(entryFile, `\n    import { message } from './temp-dependency';\n    console.log(message);\n    console.log(\"This is the main entry point.\");\n  `);\n\n  console.log('Starting Bundlex quickstart...');\n\n  try {\n    // Set up a listener for file changes\n    jsBundler.on('change', (changedPath: string) => {\n      console.log(`[Bundlex Watch] Detected change in: ${changedPath}.`);\n      console.log('Re-bundling logic would typically go here...');\n    });\n\n    // Bundle the entry file\n    const bundledContent = await jsBundler(entryFile);\n\n    console.log('\\n--- Bundled Output (truncated) ---');\n    console.log(bundledContent.slice(0, 500) + '\\n...'); // Display first 500 characters\n\n    // Simulate a file change to trigger the listener\n    await new Promise(resolve => setTimeout(resolve, 50)); // Small delay\n    await fs.appendFile(depFile, `\\n// Added content to trigger change on ${Date.now()}`);\n    console.log('\\nSimulated file change. Check for listener output above.');\n\n  } catch (error) {\n    console.error('Bundlex quickstart failed:', error);\n  } finally {\n    // Clean up temporary files\n    await fs.unlink(entryFile).catch(() => {});\n    await fs.unlink(depFile).catch(() => {});\n    console.log('\\nCleaned up temporary files.');\n  }\n}\n\nrunBundlexQuickstart();","lang":"typescript","description":"Demonstrates basic bundling of TypeScript files and how to set up a file change listener using `jsBundler`."},"warnings":[{"fix":"Configure your project to use ES modules (`\"type\": \"module\"` in package.json) or ensure your target environment supports ESM. For Node.js, consider a custom bundler function with `createBundler` if specific CJS output or advanced external module handling is required.","message":"Bundlex primarily targets ESM output for modern JavaScript environments. While it processes CJS modules as inputs, the default output format is typically ESM. Direct CommonJS 'require()' calls in the bundled output for external modules might not function as expected without a transpilation step or specific configuration for Node.js environments.","severity":"gotcha","affected_versions":">=3.0.0"},{"fix":"Always use clear relative or absolute paths. For complex projects, consider implementing a custom 'infoExtractor' with `createBundler` to handle path aliases or advanced module resolution strategies tailored to your project structure.","message":"Relative path resolution within the bundler can sometimes be tricky, especially when dealing with nested directories or alias configurations. Bundlex resolves paths relative to the importing file unless explicitly configured otherwise.","severity":"gotcha","affected_versions":">=3.0.0"},{"fix":"When using the `change` listener, implement logic within your callback to explicitly re-run the `jsBundler()` function with the entry file path to generate an updated bundle.","message":"The `jsBundler.on('change', ...)` listener monitors file system changes for files included in the bundle graph. However, it might not automatically trigger a *re-bundle* operation; it merely notifies your application. You are responsible for re-invoking the `jsBundler()` function (or your custom bundler) upon receiving a 'change' event to generate an updated output.","severity":"gotcha","affected_versions":">=3.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Verify the import path is correct and the module exists. For `node_modules`, ensure it's installed. If using aliases, consider a custom `infoExtractor` with `createBundler` to handle alias resolution.","cause":"The bundler failed to resolve an import path, likely due to incorrect relative paths, a missing `node_modules` dependency, or a misconfigured alias.","error":"Cannot find module 'some-module' or its corresponding type declarations."},{"fix":"Ensure your Node.js project's `package.json` contains `\"type\": \"module\"` or ensure your runtime environment supports ESM. Bundlex's primary output is ESM, so direct CJS output options may not be available.","cause":"The bundled output is in ES Module format, but it's being executed in a CommonJS context (e.g., Node.js without `\"type\": \"module\"` in `package.json` or an older Node version).","error":"SyntaxError: Cannot use import statement outside a module"}],"ecosystem":"npm"}