Movatterモバイル変換


[0]ホーム

URL:


Hot Module Replacement

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.

hmr demo

Installation

Add Fable package with paket:paket add nuget Fable.Elmish.HMR

Webpack configuration

Addhot: true andinline: true (only for webpack < v5.0.0) to yourdevServer node.

Example:// ...devServer: {// ... hot:true}// ...

Parcel and Vite

Parcel and Vite, are supported since version 4.2.0. They don't require any specific configuration.

Usage

Limitation

Currently, Elmish.HMR only works when running asingle Elmish instance with HMR enabled.

If you need supports for multiple Elmish instances, please contribute it to Elmish.HMR via a PR.

The package will include the HMR support only if you are building your program withDEBUG set in your compilation conditions. Fable adds it by default when in watch mode.

You need to always includeopen Elmish.HMR after your othersopen Elmish.XXX statements. This is needed to shadow the supported APIs.

For example, if you useElmish.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

You can also useElmish.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)


[8]ページ先頭

©2009-2025 Movatter.jp