tupac: Ghetto In-Browser JavaScript Bundler
tupac (version 0.2.3) is a command-line tool designed as a minimalistic, zero-configuration JavaScript bundler for in-browser development. It provides features like hot module reloading and code splitting with minimal overhead. Unlike modern bundlers like Webpack, Rollup, or Esbuild, tupac operates by implementing a custom CommonJS-like `require` system directly in the browser, compiling modules asynchronously. Its key differentiators include its extreme simplicity and lack of configuration, making it quick to set up for small, pure JavaScript projects. However, it explicitly states it's 'NOT FOR PRODUCTION' and lacks support for TypeScript, JSX, or comprehensive ES6 module features. The package appears to be abandoned, with no significant updates or active development, reflecting its early-stage version and niche use case as a 'ghetto bundler.'
Common errors
-
ReferenceError: require is not defined
cause Attempting to use `require` in a browser environment without tupac's custom bundling and runtime, or outside the scope of a tupac-bundled script.fixEnsure your script is being served and processed by `tupac` via the `tupac` command. The `require` function is injected by the bundler into the browser environment. -
SyntaxError: Unexpected token '<'
cause Attempting to use JSX syntax (.jsx, .tsx files) in a tupac-bundled application.fixtupac does not support JSX. Convert your components to pure JavaScript using `React.createElement` or similar patterns, or switch to a bundler that supports JSX (e.g., Webpack, Parcel, Vite). -
SyntaxError: Cannot use import statement outside a module
cause Using ES module `import` syntax within a file processed by tupac, which primarily uses a custom CommonJS-like `require` system.fixRefactor your module dependencies to use tupac's custom `require('module-name')` syntax. If you need robust ES module support, tupac is not the appropriate tool.
Warnings
- breaking tupac is explicitly 'NOT FOR PRODUCTION USE'. It lacks the robustness, security, and optimization features required for production deployments and should only be used for simple development environments.
- gotcha tupac offers 'pure JS only' and 'little support for es6 modules'. It does not support modern JavaScript tooling like TypeScript or JSX, requiring developers to stick to ES5 or older ES6 syntax, and potentially custom solutions for CSS-in-JS.
- gotcha tupac operates with a custom, in-browser `require` function and places modules and helper globals (`__tupac_modules__`, `__tupac_get_default__`, `process` mock) directly on the `window` object. This deviates from standard CommonJS or ES Module patterns.
- gotcha The project appears to be abandoned, with no recent updates or active maintenance. This means no new features, bug fixes, or security patches will be released, making it unsuitable for any project requiring ongoing support.
Install
-
npm install tupac -
yarn add tupac -
pnpm add tupac
Imports
- require
import { words } from 'lodash'; const words = require('lodash/words'); // In a Node.js contextdocument.body.textContent = require('lodash/words')('Reality is wrong. Dreams are for real.').join(' - ') - window.addEventListener('hotreload', ...)
window.addEventListener('hotreload', ({ detail: module }) => console.log('Hot reloaded:', module)); - __tupac_modules__
console.log(window.__tupac_modules__);
Quickstart
mkdir my-thug-project-js && cd "$_"
yarn init -y
yarn add lodash
echo "document.body.textContent = require('lodash/words')('Reality is wrong. Dreams are for real.').join(' - ')" >> app.js
tupac