question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[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:closed
  • Created 6 years ago
  • Reactions:6
  • Comments:5

github_iconTop GitHub Comments

2reactions
johnwilhitecommented, Jan 25, 2019

@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

0reactions
bruno-fernandescommented, Jan 26, 2019

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found