Rollup Development Server Plugin

0.7.0 · maintenance · verified Tue Apr 21

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

Warnings

Install

Imports

Quickstart

This quickstart demonstrates configuring `rollup-plugin-server` to serve a basic Rollup bundle from a 'dist' directory, automatically opening the browser to `http://localhost:10001`.

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
    })
  ]
};

view raw JSON →