Unavailable. Nobody can download this version any more, with elm or with the Lamdera compiler: github.com/CancerAidDev/elm-pages exists but has no tag 1.1.0; Software Heritage has not archived the repo; no fork with tag 1.1.0 found (60 same-name repos checked); no cached copy. Use another version.
In a vanilla Elm application, ports let you either send or receive JSON data between your Elm application and the JavaScript context in the user's browser at runtime.
With
DataSource.Port, you send and receive JSON to JavaScript running in NodeJS during build-time. This means that you can call shell scripts, or run NPM packages that are installed, or anything else you could do with NodeJS.A
DataSource.Portwill call an async JavaScript function with the given name. The function receives the input JSON value, and the Decoder is used to decode the return value of the async function.Here is the Elm code and corresponding JavaScript definition for getting an environment variable (or a build error if it isn't found).
Error Handling
port-data-source.jsAny time you throw an exception from a DataaSource.Port definition, it will result in a build error in your
elm-pages buildor dev server. In the example above, if the environment variable is not found it will result in a build failure. Notice that the NPM packagekleuris being used in this example to add color to the output for that build error. You can use any tool you prefer to add ANSI color codes within the error string in an exception and it will show up with color output in the build output and dev server.Performance
As with any JavaScript or NodeJS code, avoid doing blocking IO operations. For example, avoid using
fs.readFileSync, because blocking IO can slow down your elm-pages builds and dev server.