Set environment variable using command line arguments
See original GitHub issueI’m submitting a feature request
- Library Version:
CLI
0.26.0
Framework1.0.8
Please tell us about your environment:
-
Operating System: Windows 10
-
Node Version: 6.9.4
-
NPM Version: 4.1.1
-
Browser: Chrome 56 but it’s not browser related
-
Language: TypeScript 2.1.5
I’d sometimes need the possibility to set the value of a specific environment variable using a command line argument.
E.g. I’d like to set a version number which is generated by my build server:
aurelia_project/environments/prod.ts
export default {
debug: false,
testing: false,
// $buildVersion$ should be replaced during build with the actual value
buildVersion: $buildVersion$
};
Imaginary command: au build --env prod --buildVersion 1.1.1
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Set an Environment Variable in Windows - Command Line ...
To set persistent environment variables at the command line, we will use setx.exe . It became part of Windows as of Vista/Windows Server...
Read more >set (environment variable) - Microsoft Learn
Displays, sets, or removes cmd.exe environment variables. If used without parameters, set displays the current environment variable settings.
Read more >Using the command prompt to change environment variables
The following diagram shows the syntax for setting an environment variable at a command prompt in Windows. If no value is specified, the...
Read more >Argument passing strategy - environment variables vs ...
An environmental variable is simply a pair, VARIABLE=value . Command line arguments can be much more complicated: they can be positional or ...
Read more >How to Change your Command Line Environment
Setting Environment Variables on the Fly · Set the variable on its own line, then use it anywhere: $ SOMETHING="some value" $ echo...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Perfect, this is exactly the hook I was looking for. Thanks for the tip!
Quick note, the
src/environtment.ts
file is modified at build time to reflect how you are trying to run. If you run with the dev environment, the file will have the options that represent that (as configured by theaurelia.json
file). So if you manually modified it, and then ran, then that file would have been updated with your build instructions.Now, the
src/environments
should be what is pulled down when you ask for it, as you can see this in themain.js
of the skeleton project. The reason you’re not getting your updated file contents is because of the order in which you are processing your files. If you look at thetranspile
task, that is where the environment variables are read in and the appropriate file copied. But also inside here is where we transpile/build the code. Which means your replacement function is happening after the code is transpiled, and therefore not being brought into your bundle.To solve your problem, simply do your replace function inside the
transpile.js
configureEnvironment
function, since that is where you should be doing this kind of configuration.So, your
configureEnvironment
function simply is modified to look like this (this is for ES, fyi, but the solution is identical).That’s it, that’s all it takes 😃 Let me know if this still doesn’t work, or if you have any more questions.