Nollup: Rollup-compatible Dev Bundler
Nollup is a Rollup-compatible bundler specifically engineered for rapid development workflows, currently at version 0.21.0. Unlike Rollup, which focuses on production-optimized bundles through aggressive tree-shaking and scope-hoisting, Nollup intentionally skips these optimizations to achieve exceptionally fast rebuild times. This makes it ideal for local development, enabling features like Hot Module Replacement (HMR) using existing `module.hot` conventions. It maintains compatibility with standard Rollup plugins and configuration files, allowing developers to leverage their existing Rollup ecosystem for application development. Nollup offers several modes of operation, including a CLI, Dev Server API, Dev Middleware API, and Compiler API, supporting frequent releases with a focus on developer experience.
Common errors
-
Something imported is undefined.
cause Nollup disables ESM live-bindings by default for performance reasons, which can lead to `undefined` values for mutable exports.fixEnable live-bindings in your Nollup configuration: `output: { ..., liveBindings: true }`. -
Error: Cannot find module '<module-id>' (usually with a numeric ID)
cause This error typically occurs when a CommonJS module is used without the `@rollup/plugin-commonjs` being correctly configured or if the plugin fails to transform an unusually structured CommonJS module.fixEnsure `@rollup/plugin-node-resolve` and `@rollup/plugin-commonjs` are installed and correctly configured in your Nollup plugins array. Verify that the CommonJS plugin is applied before other plugins that might process the code. -
Sourcemaps are incorrect or not generated for TypeScript files.
cause A bug in Nollup versions prior to 0.18.7 prevented proper sourcemap generation and display for plugins like `@rollup/plugin-typescript`.fixUpdate Nollup to version 0.18.7 or later to resolve sourcemap issues. Also, ensure your TypeScript plugin is up-to-date and correctly configured. -
Dynamic imports break when emitting assets or cause runtime errors.
cause A specific bug in Nollup versions prior to 0.18.4 caused dynamic imports to malfunction when combined with asset emission, leading to broken imports or runtime failures.fixUpgrade Nollup to version 0.18.4 or later to fix issues related to dynamic imports and asset emission.
Warnings
- gotcha Nollup is strictly for development and does not perform production-level optimizations like Rollup (e.g., tree-shaking, scope-hoisting). Bundles generated by Nollup are not suitable for production deployment due to their larger size and lack of optimizations.
- gotcha ESM live-bindings are disabled by default for performance. If your application relies on mutable exports (e.g., `export let count = 0;` and then `count++` in another module), you might encounter `undefined` values or unexpected behavior.
- gotcha Nollup only implements Rollup configuration options that are relevant for development. Options primarily focused on production optimizations or niche scenarios may be ignored without warning, leading to discrepancies with your production Rollup build.
- gotcha Older versions of Nollup (pre-0.18.5) had issues with Hot Module Replacement (`module.hot.accept()`) when used without a callback function, preventing HMR from functioning correctly in those scenarios.
- gotcha The behavior for IIFE external imports changed in version 0.20.1, specifically how global variables are searched when a default import is assigned to a variable. This might affect applications relying on specific global variable remapping in IIFE bundles.
- gotcha TypeScript sourcemaps generated by plugins were not correctly displayed in some setups due to a bug in Nollup.
Install
-
npm install nollup -
yarn add nollup -
pnpm add nollup
Imports
- createServer
const { createServer } = require('nollup');import { createServer } from 'nollup'; - createCompiler
const { createCompiler } = require('nollup');import { createCompiler } from 'nollup'; - nollupCLI
import { runCLI } from 'nollup';npx nollup
Quickstart
import { createServer } from 'nollup';
import path from 'path';
import { fileURLToPath } from 'url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
// Minimal rollup config (e.g., rollup.config.js)
const rollupConfig = {
input: path.resolve(__dirname, 'src/main.js'),
output: {
file: 'dist/bundle.js',
format: 'esm',
sourcemap: true,
},
plugins: [], // Add your Rollup plugins here, e.g., @rollup/plugin-node-resolve(), @rollup/plugin-commonjs()
};
// Create a basic server.js file to start Nollup
async function startDevServer() {
const server = await createServer({
config: rollupConfig,
port: process.env.PORT ?? 9000,
contentBase: path.resolve(__dirname, 'public'),
hot: true, // Enable Hot Module Replacement
});
server.listen();
console.log(`Nollup dev server listening on http://localhost:${server.port}`);
}
startDevServer().catch(console.error);
// --- src/main.js ---
// console.log('Hello from Nollup!');
// document.body.innerHTML = '<h1>Hello Nollup Dev!</h1>';
// --- public/index.html ---
// <!DOCTYPE html>
// <html lang="en">
// <head>
// <meta charset="UTF-8">
// <meta name="viewport" content="width=device-width, initial-scale=1.0">
// <title>Nollup App</title>
// </head>
// <body>
// <script src="/dist/bundle.js"></script>
// </body>
// </html>
// To run:
// 1. Create files: server.js, src/main.js, public/index.html as above.
// 2. Add "type": "module" to your package.json.
// 3. Install: npm install nollup
// 4. Run: node server.js