Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

rollup-plugin-serve

thgh122.1kMIT1.1.1

Serve your rolled up bundle

rollup, rollup-plugin, serve, dev-server, static

readme

Rollup plugin to serve the bundle

Software License Issues JavaScript Style Guide NPM Latest Version

Installation

# Rollup v0.60+ and v1+
npm install --save-dev rollup-plugin-serve

# Rollup v0.59 and below
npm install --save-dev rollup-plugin-serve@0

Usage

// rollup.config.js
import serve from 'rollup-plugin-serve'

export default {
  input: 'src/main.js',
  output: {
    file: 'dist/bundle.js',
    format: ...
  },
  plugins: [
    serve('dist')
  ]
}

Options

By default it serves the current project folder. Change it by passing a string:

serve('public')    // will be used as contentBase

// Default options
serve({
  // Launch in browser (default: false)
  open: true,

  // Page to navigate to when opening the browser.
  // Will not do anything if open=false.
  // Remember to start with a slash.
  openPage: '/different/page',

  // Show server address in console (default: true)
  verbose: false,

  // Folder to serve files from
  contentBase: '',

  // Multiple folders to serve from
  contentBase: ['dist', 'static'],

  // Set to true to return index.html (200) instead of error page (404)
  historyApiFallback: false,

  // Path to fallback page
  historyApiFallback: '/200.html',

  // Options used in setting up server
  host: 'localhost',
  port: 10001,

  // By default server will be served over HTTP (https: false). It can optionally be served over HTTPS
  https: {
    key: fs.readFileSync('/path/to/server.key'),
    cert: fs.readFileSync('/path/to/server.crt'),
    ca: fs.readFileSync('/path/to/ca.pem')
  },

  //set headers
  headers: {
    'Access-Control-Allow-Origin': '*',
    foo: 'bar'
  },

  // set custom mime types, usage https://github.com/broofa/mime#mimedefinetypemap-force--false
  mimeTypes: {
    'application/javascript': ['js_commonjs-proxy']
  }

  // execute function after server has begun listening
  onListening: function (server) {
    const address = server.getAddress()
    const host = address.host === '::' ? 'localhost' : address.host
    // by using a bound function, we can access options as `this`
    const protocol = this.https ? 'https' : 'http'
    console.log(`Server listening at ${protocol}://${host}:${address.port}/`)
  }
})

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Contributions and feedback are very welcome.

This project aims to stay lean and close to standards. New features should encourage to stick to standards. Options that match the behaviour of webpack-dev-server are always ok.

To get it running:

  1. Clone the project.
  2. npm install
  3. npm run build

Credits

License

The MIT License (MIT). Please see License File for more information.

changelog

Changelog

All notable changes to rollup-plugin-serve will be documented in this file.

[1.1.0] - 2020-11-01

Added

  • Add onListening hook #69 @filoxo
  • Show error message when port is in use #60 @jaeh

[1.0.4] - 2020-08-28

Added

  • Add mimeTypes option #58 @GerardRodes

Fixed

  • Allow opening the browser even when verbose mode is disabled #64 @Richienb

[1.0.3] - 2020-07-21

Fixed

  • Fix path.normalize error on Windows

[1.0.2] - 2020-07-17

Fixed

  • Fix path traversal issue

[1.0.1] - 2019-01-27

Added

  • Add Intellisense support #34

Fixed

  • Set minimum version for mime package

1.0.0 - 2019-01-11

Fixed

  • Update ongenerate to generateBundle

Removed

  • Remove built-in favicon.ico #20

0.6.1 - 2018-12-23

Added

  • Add support for rollup --watch (Release http server on rollup reload)

0.5.0 - 2018-09-18

Added

  • Allow to override path for historyApiFallback option
  • Option openPage

Fixed

  • Fix host option

0.4.2 - 2017-08-25

Added

  • Option https

0.4.1 - 2017-08-16

Added

  • Option headers

Fixed

  • Close the server when a termination signal is encountered

0.4.0 - 2017-07-02

Fixed

  • Various fixes to contentBase handling

0.3.0 - 2017-04-07

Changed

  • Allow to pass array as contentBase

0.2.0 - 2017-04-07

Changed

  • Show console message only once

0.1.0 - 2016-09-29

Added

  • Option open open the project in browser
  • Option historyApiFallback
  • Default green favicon

Changed

  • Option root is now contentBase

0.0.1 - 2016-09-24

Added

  • Initial version