1.1.0 • Published 2 years ago
@blakerutledge/per-env v1.1.0
blakerutledge fork
- Include dependency on dotenv to use
.envfile. Walks up the filepath looking for it in case you have a nested type project setup. - Add ability to specify an arbitrary .env key beside
NODE_ENV. In npm script, the first argument passed after callingper-envoverrides the default key.
in .env file you can have:..., "build": "per-env", "build:dev": "build dev things", "build:prod": "build prod things", "start": "per-env SUB_APP", "start":my_app_1': "node app_1.js", "start":my_app_2': "node app_2.js" ... }NODE_ENV=dev SUB_APP=my_app_1
per-env
Clean up your
package.jsonwith per-NODE_ENVnpm scripts.
Features
- Defaults
NODE_ENVtodevelopment. - Customize
process.envper-environment. - Clearer, concise scripts.
- No more Bash-scripting in
package.json. - Simplify your workflow:
npm installnpm start
Example
{
// Processes spawned by `per-env` inherit environment-specific
// variables, if defined.
"per-env": {
"production": {
"DOCKER_USER": "my",
"DOCKER_REPO": "project"
}
},
"scripts": {
// If NODE_ENV is missing, defaults to "development".
"build": "per-env",
"build:development": "webpack -d --watch",
"build:staging": "webpack -p",
"build:production": "webpack -p",
// Deployment won't work unless NODE_ENV=production is explicitly set.
"deploy": "per-env",
"predeploy:production": "docker build -t ${DOCKER_USER}/${DOCKER_PROJECT} .",
"deploy:production": "docker push ${DOCKER_USER}/${DOCKER_PROJECT}",
// "npm start" is _the_ command to start the server across all environments.
"start": "per-env",
"start:development": "npm run build:development",
"prestart:production": "npm run build",
"start:production": "start-cluster build/server/server.js",
"prestart:staging": "npm run build",
"start:staging": "start-cluster build/server/server.js",
// Explicitly set NODE_ENV, which is helpful in CI.
"test": "NODE_ENV=test per-env",
"test:test": "mocha"
}
}Installation
npm:
$ npm install @blakerutledge/per-env
yarn:
$ yarn add @blakerutledge/per-env
License
MIT License 2016 © Eric Clemmons
1.1.0
2 years ago