Elmish applications can benefit from Hot Module Replacement (known as HMR).
This allow us to modify the application while it's running, without a full reload. Your application will now maintain its state between two changes.
Add Fable package with paket: Add Example: Parcel and Vite, are supported since version 4.2.0. They don't require any specific configuration. The package will include the HMR support only if you are building your program with You need to always include For example, if you use You can also usepaket add nuget Fable.Elmish.HMR
Webpack configuration
hot: true
andinline: true
(only for webpack < v5.0.0) to yourdevServer
node.// ...devServer: {// ... hot:true}// ...
Parcel and Vite
Usage
DEBUG
set in your compilation conditions. Fable adds it by default when in watch mode.open Elmish.HMR
after your othersopen Elmish.XXX
statements. This is needed to shadow the supported APIs.Elmish.Program.run
it will be shadowed asElmish.HMR.Program.run
.openElmishopenElmish.ReactopenElmish.HMR// See how this is the last open statementProgram.mkProgram init update view|> Program.withReactSynchronous"elmish-app"|> Program.run
Elmish.Program.runWith
if you need to pass custom arguments,runWith
will also be shadowed asElmish.HMR.Program.runWith
:Program.mkProgram init update view|> Program.withReactSynchronous"elmish-app"|> Program.runWith("custom argument",42)