Serverless Dotenv Component
npm install @slsplus/dotenv

Inspired by serverless-dotenv-plugin.
Preload environment variables into serverless. If you have variables stored in a .env file that you want loaded into your serverless yaml config. This will allow you to reference them as \${Dotenv.env.VAR_NAME} inside your config(If you ).
Add @slsplus/dotenv in your serverless.yml, as below:
``yml`
Dotenv:
component: '@slsplus/dotenv'
Now create .env file in the project root:
`yml
TENCENT_SECRET_ID=xxx
TENCENT_SECRET_KEY=xxx
ABC=124
`
By default, the component looks for the file: .env. If you want different env files based on environment. For example:
``
.env.development
.env.production
Then you can exec deploy command like:
`bash`
$ NODE_ENV=development serverless --debug
Or, like this:
`bash`
$ serverless --debug --env development
You can directly run deploy command with custom arguments:
`bash`
$ serverless --debug --custom abc --custom1 123
Then you can use by process.env.custom and process.env.custom1
#### Complete configuration in serverless.yml
`ymlserverless.yml
Dotenv:
component: '@serverless/dotenv-component'
inputs:
envFile: /path/to/my/.env
envPath: /path/to/my/
exclude:
- SECRET
`
#### Configuration description
| Param | Required/Optional | Type | Default | Description |
| ------- | ----------------- | ------ | --------------- | ----------------------------------------------- |
| envFile | Optional | String | .env | Dotenv file |
| envPath | Optional | String | process.cwd()` | Dotenv file path |
| exclude | Optional | string | [] | Variable in .env file, you don't want to expose |
Copyright (c) 2020 Serverless Plus