Skip to content

Instantly share code, notes, and snippets.

@juliosguz
Created August 11, 2017 12:52
Show Gist options
  • Save juliosguz/fae9a7aa508c1abd81bb108e4e0557f1 to your computer and use it in GitHub Desktop.
Save juliosguz/fae9a7aa508c1abd81bb108e4e0557f1 to your computer and use it in GitHub Desktop.
Use OS environment variable to get configuration on Angular
// 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