Created
August 11, 2017 12:52
-
-
Save juliosguz/fae9a7aa508c1abd81bb108e4e0557f1 to your computer and use it in GitHub Desktop.
Use OS environment variable to get configuration on Angular
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This script is based from https://medium.com/@natchiketa/angular-cli-and-os-environment-variables-4cfa3b849659 | |
import { writeFile } from 'fs'; | |
import { argv } from 'yargs'; | |
const environment = argv.environment; | |
const isProd = environment === 'prod'; | |
require('dotenv').config({path: `./set-env/.env.${environment}`}); | |
const targetPath = `./src/environments/environment.${environment}.ts`; | |
const envConfigFile = ` | |
export const environment = { | |
production: ${isProd} | |
}; | |
`; | |
writeFile(targetPath, envConfigFile, function (err) { | |
if (err) { | |
console.log(err); | |
} | |
console.log(`Output generated at ${targetPath}`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment