Rollup Development Server Plugin
rollup-plugin-server is a Rollup plugin that provides a basic development server for serving bundled applications. It simplifies the development workflow by allowing developers to serve static files from specified content base directories, enabling quick testing of Rollup output in a browser. The plugin supports features like history API fallback, custom host and port configuration, and optional HTTPS serving using user-provided SSL certificates. The current stable version is 0.7.0, with no recent updates, suggesting a maintenance-mode project rather than active feature development. Its primary differentiation lies in its direct integration into the Rollup configuration for a lightweight, build-time server.
Common errors
-
Error: listen EADDRINUSE: address already in use :::10001
cause The configured server port (e.g., 10001) is already being used by another application or a previous instance of your development server.fixChange the `port` option in your `server()` plugin configuration to an unused port number (e.g., 10002) or terminate the process currently occupying the port. -
ENOENT: no such file or directory, open 'path/to/server.key'
cause The `ssl_key` or `ssl_cert` option in your server configuration points to a file that does not exist at the specified path.fixVerify that the paths provided to `fs.readFileSync()` for `ssl_key` and `ssl_cert` are correct and that the files exist relative to where your Rollup configuration is run. -
RollupError: Could not resolve entry.js
cause Rollup cannot find the entry file specified in your `input` (or deprecated `entry`) configuration. This is often a pathing issue or the file doesn't exist.fixEnsure the `input` path in your Rollup configuration correctly points to an existing JavaScript entry file. Use `path.resolve(__dirname, 'your-entry.js')` for robustness.
Warnings
- gotcha The plugin is currently at version 0.7.0 and has not seen updates for several years. While functional, it might not be actively maintained, and future Rollup versions could introduce incompatibilities.
- gotcha When using `ssl: true`, the `ssl_key` and `ssl_cert` options require the actual certificate and key content (e.g., read using `fs.readFileSync`), not just their file paths. Improperly formatted or invalid certificate data will cause the HTTPS server to fail.
- gotcha If the specified `port` (default 10001) is already in use by another process, the server will fail to start without a clear message in some environments. This can lead to silent failures or errors related to address binding.
- deprecated The README and examples show `entry` and `dest` options in the Rollup config. These options are deprecated in modern Rollup versions (>=1.0) in favor of `input` and `output.file` or `output.dir`.
Install
-
npm install rollup-plugin-server -
yarn add rollup-plugin-server -
pnpm add rollup-plugin-server
Imports
- server
const server = require('rollup-plugin-server')import server from 'rollup-plugin-server'
- server
server({ contentBase: ['dist'], open: 'true' })server({ open: true, contentBase: 'dist' }) - ssl_key
ssl_key: 'server.key'
import fs from 'fs'; /* ... */ ssl_key: fs.readFileSync('server.key')
Quickstart
import server from 'rollup-plugin-server';
import path from 'path';
import fs from 'fs';
// Create a dummy entry file for Rollup to process
const entryFilePath = path.resolve(__dirname, 'entry.js');
fs.writeFileSync(entryFilePath, 'console.log("Hello from Rollup bundle!");');
// Create a dummy dist directory and an index.html
const distDirPath = path.resolve(__dirname, 'dist');
if (!fs.existsSync(distDirPath)) {
fs.mkdirSync(distDirPath);
}
const indexHtmlPath = path.join(distDirPath, 'index.html');
fs.writeFileSync(indexHtmlPath, '<!DOCTYPE html>\n<html><head><title>Rollup App</title></head><body><div id="app"></div><script src="bundle.js"></script></body></html>');
export default {
input: entryFilePath,
output: {
file: path.join(distDirPath, 'bundle.js'),
format: 'esm'
},
plugins: [
server({
open: true, // Automatically open the browser
verbose: true, // Show server address in console
contentBase: distDirPath, // Serve files from the 'dist' directory
host: 'localhost',
port: 10001,
historyApiFallback: true // Serve index.html for 404s
})
]
};