rollup-endpoint

raw JSON →
0.2.2 verified Mon Apr 27 auth: no javascript

Serve a Rollup-bundled JavaScript file directly from an Express.js endpoint with minimal configuration. Current stable version is 0.2.2. It builds bundles on the fly during development and enables caching with gzip in production via the NODE_ENV environment variable. Differentiators include zero build step integration, automatic caching, and support for all Rollup options including plugins and generate options. Ideal for rapid prototyping or simple SPAs without a separate build system.

error Cannot find module 'rollup'
cause Missing peer dependency 'rollup' required by rollup-endpoint.
fix
Run: npm install rollup --save
error TypeError: rollupEndPoint.serve is not a function
cause Incorrect import pattern; likely using destructuring on require.
fix
Use: const rollupEndPoint = require('rollup-endpoint'); app.get('/bundle.js', rollupEndPoint.serve({...}));
error ReferenceError: require is not defined
cause Running the module in an ESM environment (e.g., Node.js with type: module) where require is not available.
fix
Use import syntax or rename file to .cjs to force CommonJS.
error Error: `options.input` must be a string or array of strings
cause Using the deprecated 'entry' option instead of 'input' with Rollup >=1.
fix
Replace 'entry' with 'input' in the options object.
gotcha Cache only works when NODE_ENV is set to 'production'. Without it, the bundle is rebuilt on every request in development. This can cause high CPU usage and slow responses.
fix Ensure NODE_ENV=production in production environments. For development, consider using nodemon or similar to restart automatically on changes.
deprecated The generateOptions.format option 'es6' is deprecated in Rollup >=0.47.0 and may cause silent failures or unexpected behavior.
fix Use 'es' for ES module format instead of 'es6'.
gotcha Rollup plugins must be configured per request; if you pass a plugin array in the options, it will be reused across requests. This can lead to memory leaks if plugins hold state (e.g., rollup-plugin-visualizer).
fix Create a new plugin instance for each request by using a factory function, or ensure plugins are stateless.
breaking Rollup 2.0 uses ES module syntax for configuration and options. The package rollup-endpoint (pre-Rollup 2) expects the CommonJS API. Using Rollup >=2 may break the bundle generation.
fix Pin Rollup to version 1.x (e.g., "rollup": "^1.0.0") or update to a compatible package.
deprecated The 'entry' option has been renamed to 'input' in Rollup version 1.0.0 and later. Using 'entry' will now throw an error or be ignored.
fix Use 'input' instead of 'entry' when specifying the bundle entry point.
npm install rollup-endpoint
yarn add rollup-endpoint
pnpm add rollup-endpoint

Creates an Express server that serves a Rollup-bundled JavaScript file from client/main.js, with production plugins for transpilation and minification.

// server.js
const rollupEndpoint = require('rollup-endpoint');
const express = require('express');
const app = express();

app.get('/bundle.js', rollupEndpoint.serve({
  entry: require('path').join(__dirname, 'client', 'main.js'),
  plugins: process.env.NODE_ENV === 'production'
    ? [
        require('rollup-plugin-buble')(),
        require('rollup-plugin-uglify')()
      ]
    : []
}));

app.listen(3000, () => console.log('Server running on port 3000'));