Lionel CommonJS Bundler

1.1.1 · maintenance · verified Tue Apr 21

Lionel CommonJS Bundler is a lightweight JavaScript module bundler designed to transform CommonJS modules into a single, browser-compatible JavaScript file. It is currently at version 1.1.1, with its last update approximately three years ago, suggesting a maintenance rather than actively developed phase. The bundler prioritizes simplicity and ease of use, offering minimal configuration options, which differentiates it from more complex tools like Webpack or Rollup. Its primary runtime dependency is `uglify-js` for minification. The bundler is notably used by the Lionel App by default. It supports bundling both directly from code content and from specified file paths.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to use `makeFile` to bundle a CommonJS JavaScript file along with its local dependencies into a single browser-compatible string.

const { commonJSBundler } = require('lionel-commonjs-bundler/index');
const path = require('path');

const contentOfFile = `
  const dep = require('./dependency');
  module.exports = 'Hello ' + dep;
`;

const dependencyContent = `
  module.exports = 'World';
`;

// Create dummy files for demonstration
const fs = require('fs');
const tempDir = path.join(__dirname, 'temp_bundler_test');
if (!fs.existsSync(tempDir)) fs.mkdirSync(tempDir);
fs.writeFileSync(path.join(tempDir, 'main.js'), contentOfFile);
fs.writeFileSync(path.join(tempDir, 'dependency.js'), dependencyContent);

try {
  const bundle = commonJSBundler.makeFile(path.join(tempDir, 'main.js'), tempDir);
  console.log('Successfully bundled code:\n', bundle);
  // Expected output (minified): 'var dep=require("./dependency");module.exports="Hello "+dep;' (after resolution)
} catch (error) {
  console.error('Bundling failed:', error);
} finally {
  // Clean up dummy files
  fs.unlinkSync(path.join(tempDir, 'main.js'));
  fs.unlinkSync(path.join(tempDir, 'dependency.js'));
  fs.rmdirSync(tempDir);
}

view raw JSON →