Given a pubilc/
directory layout
$ tree public
public/
├── images
│ ├── favicon.ico
│ └── logo.55e79e5927a639d21a1b.svg
├── index.html
└── manifest.ad717f2466ce655fff5c.json
1 directory, 4 files
Running files-as-elm-methods.js on it will give us
$ files-as-elm-methods.js public
module Files exposing
( imagesFaviconIco
, imagesLogoSvg
, indexHtml
, manifestJson
)
imagesFaviconIco : String
imagesFaviconIco = "/images/favicon.ico"
imagesLogoSvg : String
imagesLogoSvg = "/images/logo.55e79e5927a639d21a1b.svg"
indexHtml : String
indexHtml = "/index.html"
manifestJson : String
manifestJson = "/manifest.ad717f2466ce655fff5c.json"
Then use it like
import Files
view : Html msg
view = img [ src Files.imagesLogoSvg ] []
Don't add
Files.elm
into code repository. Instead, only generate it when necessary: locally, before tests on CI, after building assets beforeelm make
...With function-level dead code elimination we don't even need to care if the generated
Files.elm
included references to files that we don't use in our app 🤷♂️