A Vite plugin for seamlessly integrating Elm into your Vite project with reliable Hot Module Replacement (HMR) powered by elm-watch, full-color error overlays, and JS minification for production builds. Current stable version is 1.4.4. The plugin supports multiple Elm compiler modes (debug, optimize, minify) and can export Elm apps as standard objects or React components. It automatically patches DOM for Browser.application usage and provides clickable error links to launch your editor. Experimental but actively maintained.
npm install vite-plugin-elm-watchVerified import paths — ran on the pinned version, not inferred.
Basic setup for a Vite project with Elm: install plugin, configure in vite.config.js, and import .elm files. Shows both default and React output modes.
Wrap Elm components in a container that handles unmounting lifecycle carefully, or avoid swapping Elm/React components at runtime.
Do not rely on id attributes on the root node after Elm initialization; use class names or data attributes instead.
Ensure Vite's root configuration points to the correct project root. Previously relied on process.cwd() which could be inconsistent.
Upgrade to v1.4.0 or later for proper Browser.application support.
Update to v1.3.5 or later to fix Windows HMR path detection.
Test your specific use case thoroughly, especially HMR and React interop.
Change your vite.config.js to use import syntax: import elm from 'vite-plugin-elm-watch'. Also ensure your package.json has "type": "module" or rename file to .mjs.
If using React output, ensure the component is never swapped with a non-Elm component without proper cleanup. For standard mode, call init() before unmount.
Use a single version of Elm and ensure your bundler (Vite) handles Elm modules correctly. Avoid mixing CDN and bundled Elm.
Ensure your Elm file defines a 'main' value using Browser.element, Browser.document, or Browser.application. Also verify that the plugin output mode matches your usage.