BDR Bundler
BDR (BunDleR) is a JavaScript/TypeScript bundler inspired by `bili` and `poi`, originally designed for bundling, transforming, and developing JavaScript projects. It aimed to provide a lightweight alternative for building modern applications, leveraging TypeScript. Originally released with features for source code transformation and development server capabilities, its latest version is 1.7.0, released in September 2019. The project is currently abandoned, with its GitHub repository archived, indicating no further development or maintenance. Users should be aware that it lacks support for newer JavaScript features, security updates, and compatibility with recent Node.js and TypeScript versions, making it unsuitable for new projects or active development.
Common errors
-
TypeError: build is not a function
cause Incorrect import statement, or 'build' function is not exposed as expected when attempting to use CommonJS `require` or an outdated version of the package.fixEnsure you are using the correct ESM import: `import { build } from 'bdr'`. If using CommonJS, verify the module target in your `tsconfig.json` or try `const bdr = require('bdr'); bdr.build(...)` if it's a default export with properties. -
Error: Cannot find module 'typescript' or Module not found: Error: Can't resolve 'typescript'
cause 'typescript' is a peer dependency of 'bdr' but was not installed in the project's `node_modules`.fixInstall the specific TypeScript version required by 'bdr': `npm install typescript@^3.1.3` or `yarn add typescript@^3.1.3`. -
bdr: command not found
cause The `bdr` CLI tool is not globally installed on your system's PATH, or it is not available in the local project's `node_modules/.bin` directory.fixUse `npx bdr` to execute the local installation of the CLI, or ensure 'bdr' is listed in your project's `package.json` scripts (e.g., `"build": "bdr build"`) and run via `npm run build`. -
SyntaxError: Unexpected token '?' / Unexpected private field
cause Attempting to bundle source code that uses modern JavaScript syntax (e.g., optional chaining `?.`, nullish coalescing `??`, private class fields `#field`) which 'bdr's outdated parser cannot understand.fixThis issue is fundamental to 'bdr' being an abandoned project with an outdated parser. It cannot be fixed within 'bdr'. The only resolution is to migrate your project to a current bundler that supports these modern language features.
Warnings
- breaking The 'bdr' project is abandoned and its GitHub repository is archived. This means there will be no further updates, bug fixes, or security patches, making it unsafe for new projects or critical applications.
- breaking Due to its abandonment in 2019, 'bdr' does not support modern JavaScript syntax (e.g., optional chaining, nullish coalescing), recent TypeScript features, or newer Node.js versions.
- gotcha The peer dependency on 'typescript' is locked to '^3.1.3'. Using newer TypeScript versions (e.g., 4.x or 5.x) will likely lead to compilation errors or incompatibility issues due to changes in the TypeScript API or syntax support.
- gotcha Internal and transitive dependencies used by 'bdr' are likely outdated, posing potential security vulnerabilities (CVEs) and compatibility issues with current npm ecosystems. Using this package introduces significant supply chain risks.
Install
-
npm install bdr -
yarn add bdr -
pnpm add bdr
Imports
- build
const { build } = require('bdr')import { build } from 'bdr' - CLI Tool
bdr build // Requires global install which is not recommended.
npx bdr build [entrypoint] --outDir dist
- Configuration
import config from './bdr.config.js' // ES module config files (.mjs) were less common at the time, and direct import of configuration files is not how bundlers typically consume them.
// bdr.config.js module.exports = { entry: 'src/index.js', output: { dir: 'dist' } };
Quickstart
import { build } from 'bdr';
import path from 'path';
import fs from 'fs';
// Create a dummy source file for demonstration
const entryContent = `
console.log('Hello from BDR!');
export const greeting = 'BDR says hi!';
`;
const srcDir = path.resolve(__dirname, 'temp_bdr_src');
const entryPath = path.resolve(srcDir, 'main.js');
const distPath = path.resolve(__dirname, 'temp_bdr_dist');
fs.mkdirSync(path.dirname(entryPath), { recursive: true });
fs.writeFileSync(entryPath, entryContent);
async function runBuild() {
try {
console.log('Starting BDR build...');
await build({
entry: entryPath,
output: {
dir: distPath,
format: 'cjs', // 'cjs' or 'esm'
fileName: 'bundle.js'
}
});
console.log(`Build complete! Output in ${distPath}`);
const bundleContent = fs.readFileSync(path.join(distPath, 'bundle.js'), 'utf-8');
console.log('Bundle content preview:\n', bundleContent.substring(0, Math.min(bundleContent.length, 150)) + (bundleContent.length > 150 ? '...' : ''));
} catch (error) {
console.error('BDR build failed:', error);
} finally {
// Clean up temporary files
fs.rmSync(srcDir, { recursive: true, force: true });
fs.rmSync(distPath, { recursive: true, force: true });
console.log('Cleaned up temporary files.');
}
}
runBuild();