Skip to content

Instantly share code, notes, and snippets.

@marcosborges
Created January 28, 2019 15:31
Show Gist options
  • Save marcosborges/86b7b44d379e7e2ea72a2a098a4d0adf to your computer and use it in GitHub Desktop.
Save marcosborges/86b7b44d379e7e2ea72a2a098a4d0adf to your computer and use it in GitHub Desktop.
Angular - Trabalhando com criação dinâmica das configurações com base nas variáveis de ambiente
...
"scripts": {
"ng": "ng",
"config": "ts-node ./src/set-env.ts",
"start": "npm run config -- --environment=dev && ng serve",
"build": "npm run config && ng build --output-path=dist",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
...
const fs = require('fs');
const yargs = require('yargs');
if(!yargs.argv.environment){
const dotenv = require('dotenv');
dotenv.config();
}
const targetPath = `./src/environments/environment.ts`;
const envConfigFile = `
export const environment = {
production: true,
url_api: "${process.env.URL_API}",
token_name: "${process.env.TOKEN_NAME}",
};
`
fs.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