Add hmr example

This commit is contained in:
sigma-andex 2022-05-22 19:29:23 +01:00
parent e1d6263d4d
commit 74c799dae4
No known key found for this signature in database
GPG Key ID: C5F79968835855AB

View File

@ -106,6 +106,7 @@ If you have used HTTPure before, you'll probably want to go through the followin
* [routing-duplex](#routing-duplex)
* [startup options](#startup-options)
* [other improvements](#other-improvmenets)
* [hot module reloading](#hot-module-reloading)
### Routing-duplex
@ -244,6 +245,42 @@ main =
* Default closing handler - A default closing handler is provided so you can just stop your server using `ctrl+x` without having to worry about anything. You can deactivate it by setting `closingHandler: NoClosingHandler` in the listen options.
### Hot module reloading
With HTTPurple 🪁 you can easily set up a hot module reloading workflow:
Create an `index.js` with the content:
```javascript
import * as Main from './output/Main/index.js'
Main.main()
```
Add to `package.json`:
```json
...
"scripts": {
"hot": "spago build -w & nodemon \"node index.js\""
},
"type": "module",
...
```
Spin up:
```bash
npm run hot
```
Develop:
```bash
HTTPurple 🪁 up and running on http://0.0.0.0:8080
[nodemon] restarting due to changes...
[nodemon] restarting due to changes...
[nodemon] starting `node "node index.js" index.js`
HTTPurple 🪁 up and running on http://0.0.0.0:8080
[nodemon] restarting due to changes...
[nodemon] restarting due to changes...
[nodemon] starting `node "node index.js" index.js`
HTTPurple 🪁 up and running on http://0.0.0.0:8080
```
## License