Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module contains utilities for compiling and bundling Elm programs directly into your Haskell executable binary. It is useful for the case where you want to bundle a front-end Elm web app along with the backing services that support it, and especially for when the two components are part of the same codebase. It produces WAI Middleware, and is thus compatible with a wide range server-side frameworks.
Usage is designed to be as simple as possible. There are 3 steps:
1) Change your .cabal file to use a "Custom" build type, and add the appropriate custom build dependencies.
build-type: Custom ... custom-setup setup-depends: Cabal, base, om-elm
2) Modify your Setup.hs
file, using requireElm
.
3) Include a Middleware
template-haskell splice, using elmSite
,
in the appropriate place in your code.
See the function documnetation for more details.
Synopsis
- requireElm :: UserHooks -> UserHooks
- elmSite :: Map PathInfo FilePath -> Q (TExp Middleware)
- elmSiteDebug :: Map PathInfo FilePath -> Q (TExp Middleware)
- type PathInfo = [Text]
Documentation
requireElm :: UserHooks -> UserHooks Source #
Add the elm program requirements to a set of build hooks. This is expected to be used in your Setup.hs file thusly:
import Distribution.Simple (defaultMainWithHooks, simpleUserHooks) import System.Elm.Middleware (requireElm) main = defaultMainWithHooks (requireElm simpleUserHooks)
elmSite :: Map PathInfo FilePath -> Q (TExp Middleware) Source #
Template Haskell method to create a Middleware
that serves a set of
elm programs. The elm programs are compiled into HTML at compile time,
and that HTML is included directly in your executable.
The parameter is a map of pathInfo
s to elm program module file. The
elm program located at the file is served whenever the pathInfo matches
that of the request. Any non-matching request is forwarded to the
downstream Application
.
The typed template-haskell splice:
$$(elmSite $ Map.fromList [ (["app.js"], "elm/Your/Elm/Module/App.elm") ])
will construct a WAI Middleware
which serves the compiled elm program on
/app.js
.
elmSiteDebug :: Map PathInfo FilePath -> Q (TExp Middleware) Source #
Like elmSite
, but serve the debug elm runtime.