In this example there is a bunch of java/kotlin nonsense, but I wanted to paint as much of the picture as possible. However, the idea should be pretty universal.
arg | Outcome | Recommended Usage |
---|---|---|
dev | generate and serve with hot reload | Dev server |
prod | generate and serve without hot reload | Check website before a deploy |
regenerate | http request to regenerate website | Run manually or use it in File Watchers |
dev serve wil:
- Add additional endpoints in the server to subscribe browsers and notify that a regeneration has finished
- Add a script to the html pages that subscribes and reloads the pages when a message is receibed
While not a hot module replacement, for simple sites this is all that you need, a simple web refresh on code change. Oh right, link the regenerate process to your file watcher of choice. I use IntelliJ's file watcher plugin.
While pages served with the included server in dev mode will hot reload if the generation is executed we still have to trigger that manually. To avoid this, File Watcher plugin can be used to trigger generation when saving files.
This is the recommended configuration:
- File Type: Any
- Scope: Open Files
- Program: Point for gradlew in the root of the project
- Arguments: run --args="regenerate"
- Auto-save edited files to trigger the watcher: Checked
- Trigger on external changes: Checked (IntelliJ CSS color picker triggers an external change)
- Trigger regardless of syntax errors: Unchecked
- Show console: Always
(I might have also changed a genereal IntelliJ setting to save to disk without me pressing control+s but I am not sure about that)