1 | # Rollup plugin to serve the bundle
|
2 |
|
3 | <a href="LICENSE">
|
4 | <img src="https://img.shields.io/badge/license-MIT-brightgreen.svg" alt="Software License" />
|
5 | </a>
|
6 | <a href="https://github.com/thgh/rollup-plugin-serve/issues">
|
7 | <img src="https://img.shields.io/github/issues/thgh/rollup-plugin-serve.svg" alt="Issues" />
|
8 | </a>
|
9 | <a href="http://standardjs.com/">
|
10 | <img src="https://img.shields.io/badge/code%20style-standard-brightgreen.svg" alt="JavaScript Style Guide" />
|
11 | </a>
|
12 | <a href="https://npmjs.org/package/rollup-plugin-serve">
|
13 | <img src="https://img.shields.io/npm/v/rollup-plugin-serve.svg?style=flat-squar" alt="NPM" />
|
14 | </a>
|
15 | <a href="https://github.com/thgh/rollup-plugin-serve/releases">
|
16 | <img src="https://img.shields.io/github/release/thgh/rollup-plugin-serve.svg" alt="Latest Version" />
|
17 | </a>
|
18 |
|
19 | ## Installation
|
20 | ```
|
21 | # Rollup v0.60+ and v1+
|
22 | npm install --save-dev rollup-plugin-serve
|
23 |
|
24 | # Rollup v0.59 and below
|
25 | npm install --save-dev rollup-plugin-serve@0
|
26 | ```
|
27 |
|
28 | ## Usage
|
29 | ```js
|
30 | // rollup.config.js
|
31 | import serve from 'rollup-plugin-serve'
|
32 |
|
33 | export default {
|
34 | input: 'src/main.js',
|
35 | output: {
|
36 | file: 'dist/bundle.js',
|
37 | format: ...
|
38 | },
|
39 | plugins: [
|
40 | serve('dist')
|
41 | ]
|
42 | }
|
43 | ```
|
44 |
|
45 | ### Options
|
46 |
|
47 | By default it serves the current project folder. Change it by passing a string:
|
48 | ```js
|
49 | serve('public') // will be used as contentBase
|
50 |
|
51 | // Default options
|
52 | serve({
|
53 | // Launch in browser (default: false)
|
54 | open: true,
|
55 |
|
56 | // Page to navigate to when opening the browser.
|
57 | // Will not do anything if open=false.
|
58 | // Remember to start with a slash.
|
59 | openPage: '/different/page',
|
60 |
|
61 | // Show server address in console (default: true)
|
62 | verbose: false,
|
63 |
|
64 | // Folder to serve files from
|
65 | contentBase: '',
|
66 |
|
67 | // Multiple folders to serve from
|
68 | contentBase: ['dist', 'static'],
|
69 |
|
70 | // Set to true to return index.html (200) instead of error page (404)
|
71 | historyApiFallback: false,
|
72 |
|
73 | // Path to fallback page
|
74 | historyApiFallback: '/200.html',
|
75 |
|
76 | // Options used in setting up server
|
77 | host: 'localhost',
|
78 | port: 10001,
|
79 |
|
80 | // By default server will be served over HTTP (https: false). It can optionally be served over HTTPS
|
81 | https: {
|
82 | key: fs.readFileSync('/path/to/server.key'),
|
83 | cert: fs.readFileSync('/path/to/server.crt'),
|
84 | ca: fs.readFileSync('/path/to/ca.pem')
|
85 | },
|
86 |
|
87 | //set headers
|
88 | headers: {
|
89 | 'Access-Control-Allow-Origin': '*',
|
90 | foo: 'bar'
|
91 | }
|
92 | })
|
93 | ```
|
94 |
|
95 | ## Changelog
|
96 |
|
97 | Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
|
98 |
|
99 | ## Contributing
|
100 |
|
101 | Contributions and feedback are very welcome.
|
102 |
|
103 | 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](https://webpack.js.org/configuration/dev-server/#devserver) are always ok.
|
104 |
|
105 | To get it running:
|
106 | 1. Clone the project.
|
107 | 2. `npm install`
|
108 | 3. `npm run build`
|
109 |
|
110 | ## Credits
|
111 |
|
112 | - [Thomas Ghysels](https://github.com/thgh)
|
113 | - [All Contributors][link-contributors]
|
114 |
|
115 | ## License
|
116 |
|
117 | The MIT License (MIT). Please see [License File](LICENSE) for more information.
|
118 |
|
119 | [link-author]: https://github.com/thgh
|
120 | [link-contributors]: ../../contributors
|
121 | [rollup-plugin-serve]: https://www.npmjs.com/package/rollup-plugin-serve
|