Skip to content

Add @ngx-env/builder to the list of builders #172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
chihab opened this issue Oct 16, 2021 · 1 comment
Closed

Add @ngx-env/builder to the list of builders #172

chihab opened this issue Oct 16, 2021 · 1 comment

Comments

@chihab
Copy link
Contributor

chihab commented Oct 16, 2021

First of all, thanks for this project. It was an inspiration and a good resource for me to build the @ngx-env/builder.

I suggest to add @ngx-env/builder 👇 to the list of builders.

Usage

  1. Add @ngx-env to your CLI project
ng add @ngx-env/builder
  1. Define Environment Variables in .env
NG_APP_ENABLE_ANALYTICS=false
NG_APP_VERSION=$npm_package_version
NG_APP_COMMIT=$GITHUB_SHA
  1. Use in TS and HTML
@Component({
  selector: "app-footer",
})
export class FooterComponent {
  version = process.env.NG_APP_VERSION;
  branch = process.env.NG_APP_BRANCH_NAME;
  commit = process.env.NG_APP_COMMIT;
  analyticsFlag = process.env.NG_APP_ENABLE_ANALYTICS;
}
<!-- Same output in the spans -->
<span> {{ 'process.env.NG_APP_BRANCH_NAME' | env }} </span>
<span> {{ 'NG_APP_BRANCH_NAME' | env }} </span>
<span> {{ branch }} </span>
<!-- index.html -->
<head>
  <title>NgApp on %NG_APP_BRANCH_NAME%</title>
</head>
  1. Run your CLI commands
npm start
NG_APP_BRANCH_NAME=$GITHUB_HEAD_REF ng test
NG_APP_BRANCH_NAME=`git branch --show-current` npm run build

Documentation

Links

And please let me know if you think about any good feature to add to the project. 💙

@santoshyadavdev
Copy link
Member

Thank you @chihab, can you raise a PR for the same.

chihab added a commit to chihab/angular-builder that referenced this issue Oct 16, 2021
chihab added a commit to chihab/angular-builder that referenced this issue Oct 16, 2021
santoshyadavdev pushed a commit that referenced this issue Oct 16, 2021
@chihab chihab closed this as completed Oct 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants