rollup-plugin-serve

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

A Rollup plugin to serve bundled files during development with a configurable static server. Current stable version is 3.0.0, released sporadically with updates when needed. Key differentiators: zero-config setup, built-in HTTPS support, history API fallback for SPAs, and multiple content base directories. Compared to alternatives like rollup-plugin-dev, it is lighter and mimics webpack-dev-server options. Supports Rollup v0.60+ for v3, older versions available for earlier Rollup. Ships TypeScript types.

error Error [ERR_REQUIRE_ESM]: require() of ES Module not supported
cause Using CJS require() to import an ESM-only package.
fix
Switch to ESM import syntax or use dynamic import().
error TypeError: serve is not a function
cause Importing the package as named export { serve } instead of default export.
fix
Use import serve from 'rollup-plugin-serve'.
error Error: contentBase must be a string or array of strings
cause Passing an invalid type to contentBase option (e.g., number).
fix
Set contentBase to a string like './dist' or an array.
breaking Version 3.0.0 requires Rollup >= 0.60.0. Older Rollup versions must use rollup-plugin-serve@0.
fix Upgrade Rollup to >= 0.60.0 or use rollup-plugin-serve@0.
breaking Default export changed from named export 'serve' to default export in v1.0.0.
fix Use `import serve from 'rollup-plugin-serve'` instead of `import { serve } from 'rollup-plugin-serve'`.
deprecated The option 'openPage' is deprecated in favor of 'open' with a string value.
fix Use `serve({ open: '/different/page' })` instead of `serve({ open: true, openPage: '/different/page' })`.
gotcha Multiple contentBase directories must be provided as an array; passing a string will treat it as a single folder.
fix Use `contentBase: ['dist', 'static']` for multiple folders.
gotcha If using historyApiFallback as a string, it must start with a slash; otherwise it may be ignored.
fix Set `historyApiFallback: '/200.html'` (with leading slash).
npm install rollup-plugin-serve
yarn add rollup-plugin-serve
pnpm add rollup-plugin-serve

Minimal Rollup config using serve plugin to host the dist folder on port 3000 and open the browser.

// rollup.config.js (ESM)
import serve from 'rollup-plugin-serve'

export default {
  input: 'src/main.js',
  output: {
    file: 'dist/bundle.js',
    format: 'iife'
  },
  plugins: [
    serve({
      contentBase: 'dist',
      port: 3000,
      open: true,
      historyApiFallback: true
    })
  ]
}