UNPKG

3.93 kBMarkdownView Raw
1# Neutrino Dev Server Middleware
2[![NPM version][npm-image]][npm-url] [![NPM downloads][npm-downloads]][npm-url] [![Join Slack][slack-image]][slack-url]
3
4`neutrino-middleware-dev-server` is Neutrino middleware for starting a Webpack Dev Server for fast development cycles.
5
6## Requirements
7
8- Node.js v6.10+
9- Yarn or npm client
10- Neutrino v7
11
12## Installation
13
14`neutrino-middleware-dev-server` can be installed via the Yarn or npm clients.
15
16#### Yarn
17
18```bash
19❯ yarn add neutrino-middleware-dev-server
20```
21
22#### npm
23
24```bash
25❯ npm install --save neutrino-middleware-dev-server
26```
27
28## Usage
29
30`neutrino-middleware-dev-server` can be consumed from the Neutrino API, middleware, or presets. Require this package
31and plug it into Neutrino:
32
33```js
34// Using function middleware format
35const devServer = require('neutrino-middleware-dev-server');
36
37// Usage with default options
38neutrino.use(devServer);
39
40// Usage with custom options (default options are shown)
41neutrino.use(devServer, {
42 https: false,
43 port: 5000,
44 host: 'localhost',
45 public: 'localhost',
46 open: false,
47 contentBase: neutrino.options.source,
48 hot: true,
49 historyApiFallback: true,
50 publicPath: '/',
51 headers: {
52 host: 'localhost'
53 },
54 stats: {
55 assets: false,
56 children: false,
57 chunks: false,
58 colors: true,
59 errors: true,
60 errorDetails: true,
61 hash: false,
62 modules: false,
63 publicPath: false,
64 timings: false,
65 version: false,
66 warnings: true
67 }
68});
69```
70
71```js
72// Using object or array middleware format
73
74// Usage with default options
75module.exports = {
76 use: ['neutrino-middleware-dev-server']
77};
78
79// Usage with custom options (default options are shown)
80module.exports = {
81 use: [
82 ['neutrino-middleware-dev-server', {
83 https: false,
84 port: 5000,
85 host: 'localhost',
86 public: 'localhost',
87 open: false,
88 contentBase: neutrino.options.source,
89 hot: true,
90 historyApiFallback: true,
91 publicPath: '/',
92 headers: {
93 host: 'localhost'
94 },
95 stats: {
96 assets: false,
97 children: false,
98 chunks: false,
99 colors: true,
100 errors: true,
101 errorDetails: true,
102 hash: false,
103 modules: false,
104 publicPath: false,
105 timings: false,
106 version: false,
107 warnings: true
108 }
109 }]
110 ]
111};
112```
113
114By default this middleware will start a development server with Hot Module Replacement support on
115`http://localhost:5000`. To enable HMR with your application, read the documentation of corresponding Neutrino
116preset or middleware.
117
118It is recommended to call this middleware only in development mode when `process.env.NODE_ENV === 'development'`.
119More information about usage of Neutrino middleware can be found in the [documentation](https://neutrino.js.org/middleware).
120
121## Middleware options
122
123`neutrino-middleware-dev-server` optionally accepts an object with several options to override the default behavior.
124This object, as seen used above, can accept any
125[property that is accepted by Webpack Dev Server](https://webpack.js.org/configuration/dev-server/). In addition, you
126may also specify the following options:
127
128- `open`: Optional Boolean value to open the project in the a tab of the default browser. Default is `false`.
129
130## Contributing
131
132This middleware is part of the [neutrino-dev](https://github.com/mozilla-neutrino/neutrino-dev) repository, a monorepo
133containing all resources for developing Neutrino and its core presets and middleware. Follow the
134[contributing guide](https://neutrino.js.org/contributing) for details.
135
136[npm-image]: https://img.shields.io/npm/v/neutrino-middleware-dev-server.svg
137[npm-downloads]: https://img.shields.io/npm/dt/neutrino-middleware-dev-server.svg
138[npm-url]: https://npmjs.org/package/neutrino-middleware-dev-server
139[slack-image]: https://neutrino-slack.herokuapp.com/badge.svg
140[slack-url]: https://neutrino-slack.herokuapp.com/