[Feature request] Ability to specify which .env file to use
See original GitHub issue- Laravel Mix Version: 2.0.9
- Node Version: v8.4.0
- NPM Version: 5.5.1
- OS: macOS 10.13.2
Description:
When running npm run production
, I’d like to be able to use a different file from .env
(.env.production
) to specify the MIX_ environment variables. Is this possible currently? I see the following in the source, but the only time the envPath
param is set is in the tests.
https://github.com/JeffreyWay/laravel-mix/blob/master/src/plugins/MixDefinitionsPlugin.js#L10
function MixDefinitionsPlugin(envPath) {
expand(
dotenv.config({
path: envPath || Mix.paths.root('.env')
})
);
}
I’m currently swapping the env files with a bash script when building for production, but it seems like this could be made cleaner fairly easily with a mix option.
Thanks!
Issue Analytics
- State:
- Created 6 years ago
- Reactions:6
- Comments:5
Top Results From Across the Web
[Feature request] Ability to specify which .env file to use #1446
When running npm run production , I'd like to be able to use a different file from .env ( .env.production ) to specify...
Read more >We need to talk about the .env | Platform.sh
This is where the .env file comes into play. .env is a de facto standard for an ini-like file that contains fake environment...
Read more >Customizing Node.js .env files - LogRocket Blog
Learn how to configure a Node.js application via environment variables and customize an .env file with new environment variables.
Read more >Ability to specify which environment variables are masked by ...
I am currently trying to control my builds using 'infrastructure as code' type processes which means a lot of environment variables are being...
Read more >Environment Variables: What They Are and How To Use Them
You can easily set up .env files in a local development environment. Unlike platform-native variable managers, you do not need to deploy your ......
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
@bruno-fernandes I started looking into this a little more and the reason your suggestion isn’t working is dotenv will not overwrite env variables by default. By the time the config file is loaded, all the environment variables have already been set and dotenv will not overwrite them, but suggests doing this: https://www.npmjs.com/package/dotenv#what-happens-to-environment-variables-that-were-already-set.
I ended up creating a super simple mix plugin to accomplish this. https://github.com/johnwilhite/mix-env-file
@johnwilhite Great! I will give it a try.
I ended up creating a symlink to the root .env file because what I was trying to do was to use the same .env file across multiple templates, but this is definitely cleaner.