a development server for rollup
npm install rollup-plugin-deva development server for rollup
!a screenshot of this plugin running
compared to other plugins, this plugin:
- uses Fastify to provide the server and implement features
- while this means there are dependencies, it should also be trivial to add/modify to suit individual needs (see extend option below!)
- has additional features that may be useful
- detailed logging of requests (see screenshot)
- full proxy support
- support for a basepath in the URL
- will automatically turn itself off when _watch_ mode isn't enabled
``console`
npm install --save-dev rollup-plugin-dev
`console`
pnpm add --save-dev rollup-plugin-dev
`js
import dev from 'rollup-plugin-dev'
export default {
plugins: [
dev()
]
}
`
#### dirs
directories to serve static files from
example: dev('dist')dev({ dirs: ['dist', 'lib'] })
example: __dirname
default:
_when no other options are needed, a shortcut is available to specify one folder_
#### basePath
prefix all served files with a base path - e.g. serve from /static instead of /
example: dev({ basePath: '/static' })/
default:
#### silent
will silence all log messages, as well as the warning printed when rollup is started outside of watch mode
example: dev({ silent: true })false
default:
#### proxy
proxy a path to an upstream service
example: dev({ proxy: [{ from: '/api', to: 'http://localhost:9000/resources' }] })dev({ proxy: [{ from: '/api', to: 'http://localhost:9000/resources', opts: { preHandler: myPreHandler } }] })
example: undefined
default:
_opts can contain any valid options for fastify-http-proxy_
#### spa
serve a fallback page (for single-page apps)
example: dev({ spa: true }) // will serve index.htmldev({ spa: 'path/to/fallback.html' })
example: false
default:
_if a path is provided, it should be relative to one of the dirs being served_
_the fallback file must reside in one of the dirs being served_
#### port
the port the server should listen on
example: dev({ port: 3000 })8080
default:
_the server will automatically listen on the first available port after 8080 if the specified/default port is taken_
#### host
the host the server should listen on
example: dev({ host: '0.0.0.0' })localhost
default:
#### force
force the server to start, even if rollup isn't in watch mode
example: dev({ force: true })false
default:
#### dirname
the path to resolve any relative dirs from
example: dev({ dirname: '/Users/MyUser/Development/my-project' })undefined
default:
_this is generally not needed if one is running Rollup from package.json's scripts_
#### server
modify options the Fastify server is booted with - accepts any valid Fastify server attribute
example: dev({ server: { connectionTimeout: 3000 } })config.js
default: see and the serverDefaults export
_here be dragons - because modifying these options can wildly change server behavior, this is supported on an 'as is' basis only_
#### extend
enables full customization of the dev server, expects a Fastify plugin
example: dev({ extend: fp(async (server) => server.register(myPlugin)) })undefined
default:
#### onListen
this is a callback that runs after the server has started
example: dev({ onListen(server) { server.log.info('Hello world') }undefined`
default: