Skip to content

Instantly share code, notes, and snippets.

@supermario
Last active September 1, 2021 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save supermario/e5db91955b68222f34fc02d9b3ea833e to your computer and use it in GitHub Desktop.
Save supermario/e5db91955b68222f34fc02d9b3ea833e to your computer and use it in GitHub Desktop.
Lamdera elm-pkg-js support POC

For local development with lamdera live

lamdera live has rudimentary support for the elm-pkg-js spec.

Any JS in the /elm-pkg-js folder in the project root (so /, not /src/!) will get included and the exports.init(app) function called after Elm init.

i.e.

https://github.com/supermario/elm-pkg-js/blob/master/examples/copy-to-clipboard/src/copy-to-clipboard.js

For production with lamdera deploy

In addition to the lamdera live step, there must be a elm-pkg-js-includes.js file in root that requires all files like this:

$ cat elm-pkg-js-includes.js
// @NOTE this file will hopefully be auto-generated by elm-pkg-js in future!
// For now, its presense will mean Lamdera detects the extra JS and packages
// In future this will be more structured + restricted once the design is done

const lamdera_labs_media = require('./elm-pkg-js/lamdera-labs-media')

exports.init = async function init(app) {
  // @WARNING: this only runs for Lamdera production deploys!
  // This file will not run in Local development, an equivalent to this is
  // automatically generated in Local Development for every file in elm-pkg-js/
  lamdera_labs_media.init(app)
}

Note: the elm-pkg-js-includes.js file doesn't run locally in lamdera live, just in prod.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment