Make build-time environment variables available to your application.
Venv uses EJS to transform a template file using Node's process.env
map.
Usage: venv <cmd> [options]
Your build or deploy pipeline could include
npm install venv -g
venv process -t src\environments\environment.prod.ts
- appends
.template
to the filename passed as argumentt
- transforms that file using
process.env
as the context - saves the result to the original name supplied on the command line
-t, --templatePath the path to the template file
-h, --help show help
-v, --version current version
venv process --templatePath assets\env.js
assets\env.js.template:
(function (window) {
window.__env = window.__env || {};
window.__env.BUILD_BUILDNUMBER = '<%= env.BUILD_BUILDNUMBER %>';
}(this));
<html>
<head>
<meta charset="utf-8">
<script src="assets/env.js"></script>
</head>
<body>
<script>
console.log(__env.BUILD_BUILDNUMBER);
</script>
</body>
</html>
The CLI process may exit with the following codes:
0
: Transform succeeded without errors1
: An invalid command line argument or combination thereof was used2
: Transform failed