/rollup-plugin-server

Serve your rolled up bundle like webpack-dev-server

Primary LanguageJavaScriptMIT LicenseMIT

Rollup plugin to server the bundle

Software License Issues JavaScript Style Guide NPM Latest Version

Installation

npm install --save-dev rollup-plugin-server

Usage

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

export default {
  entry: 'entry.js',
  dest: 'bundle.js',
  plugins: [
    server('dist')
  ]
  // ssl: true, // optional
}

Options

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

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

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

  // 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 instead of 404
  historyApiFallback: false,

  // Options used in setting up server
  host: 'localhost',
  port: 10001,
  
  ssl: true, // optional
  // @see https://nodejs.org/api/https.html#https_https_createserver_options_requestlistener
  ssl_key: fs.readFileSync('server.key'), // optional
  ssl_cert: fs.readFileSync('server.crt'), // optional
  //ssl_ciphers: ... // optional Intermediate compatibility (default) @see https://wiki.mozilla.org/Security/Server_Side_TLS

  // Any data can be set in the response header
  customResponseHeaders: {
    'X-PING': 'PONG',
    // ...
  }
})

Test

HTTP

$ cd ./test
$ ../node_modules/.bin/rollup -c rollup.config.js

Browser access : http://localhost:10001, http://localhost:10001/base1, http://localhost:10001/base2

HTTPS

$ cd ./test
$ ../node_modules/.bin/rollup -c rollup.config.ssh.js

Browser access : https://localhost:10001, https://localhost:10001/base1, https://localhost:10001/base2

Contributing

Contributions and feedback are very welcome.

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.