UNPKG

1.84 kBMarkdownView Raw
1# webpack-udev-server
2A universal dev-server for [webpack].
3
4For universal javascript applications, this server adds the ability to hot-reload the rendering code on the server-side in addition to `webpack-dev-server`'s ability to do the same for the client-side.
5
6TODO:
7 * [ ] When HMR is not usable, restart the child server,
8 * [ ] If the child server crashes, restart it,
9 * [ ] Better configuration options,
10 * [ ] Implement rest of possible standard HTTP server events,
11 * [ ] Testing.
12
13## Usage
14
15Some runtime changes to your code are required for using the universal dev server.
16
17In your `server.js` file the `assets` event is fired whenever the location of and information about the client side assets change. This should be used to adjust the URL in your `<script>` tags.
18
19```javascript
20process.on('assets', ([url, stats]) => {
21 // Do stuff with asset updates
22});
23
24// Listen.
25server.listen(process.env['PORT']);
26```
27
28Your server webpack configuration file should include a reference to the hot runtime for the dev server and the hot signal runtime.
29
30```javascript
31{
32 entry: {
33 server: [
34 'webpack-udev-server/hot/dev-server'
35 'webpack/hot/signal',
36 './server.js'
37 ]
38 }
39}
40```
41
42All that's left is to run the dev server using both the server and client webpack configuration files.
43
44```sh
45# Specify the path to the server and client webpack config files.
46webpack-udev-server --assets client.js --renderer server.js
47```
48
49You can also run the server programmatically.
50
51```javascript
52import udev from 'webpack-udev-server';
53
54import assets from 'some-webpack-client-config.js';
55import render from 'some-webpack-server-config.js';
56
57const server = udev.createServer({
58 assets: assets,
59 render: render
60});
61
62server.listen(8080, () => {
63 console.log('dev server ready: ', this.address().port);
64});
65```
66
67
68[webpack]: http://www.google.com