A Parcel plugin for generating Elm file for your env vars automatically.
npm install parcel-plugin-elm-env-vars --dev
Parcel will use any installed package that begins with parcel-plugin-
as plugin automatically.
By default, any env var starting with ELM_
and the NODE_ENV
will be used.
You can customize this by creating a file called .parcel-plugin-elm-env-varsrc
at the root of your package -- or creating an entry parcel-plugin-elm-env-vars
in your package.json
-- and set it following this structure, which is the default:
{
"moduleName": "EnvVars",
"vars": [
"^NODE_ENV$",
"^ELM_*"
]
}
No config file is watched. So you will need to restart the parcel server if you update the configuration.
By default, the file will be stored in a autogenerated
folder at where parcel is being run at. At the moment it is not possible to customize the output folder.
Make sure to add the autogenerated
folder to your elm.json
file, e.g.:
{
"type": "application",
"source-directories": ["src", "autogenerated"],
"elm-version": "0.19.0",
...
}
It is recommended to add the autogenerated
folder to your .gitignore
.
With the default configuration, these env vars:
NODE_ENV='development'
ELM_API_ORIGIN='http://www.api.com'
RANDOM_SECRET='KJHa8s767as5&'
will generate this EnvVars.elm
file:
module EnvVars exposing (..)
-- This file was autogenerated by parcel-plugin-elm-env-vars.
-- Do not edit it manually.
nodeEnv : String
nodeEnv =
"development"
elmApiOrigin : String
elmApiOrigin =
"http://www.api.com"
To also include the RANDOM_SECRET
, add this var to your configuration.