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