Vue-cli: Can i place all .env files in a directory?

Created on 13 Sep 2018  路  5Comments  路  Source: vuejs/vue-cli

What problem does this feature solve?

I don't like placing all .env files in porject root , it makes my project structure look lengthy, can i make a directory to place them in it ?
image

What does the proposed API look like?

I can config it in vue.config.js

feature request

Most helpful comment

I have the exact same issue as @chenxeed
As a workaround I installed node-env-run as a dev dependency, and now my dev script looks like:

"dev": "nodenv --env ../../.env --exec 'vue-cli-service serve'",

Not ideal but works for now.

All 5 comments

@LinusBorg I'm working on it and I thought to add a new option environmentsDir into vue.config.js.
Is it a good solution ?
Because I have just seen that it's possible to change the vue.config.js location using an env variable (process.env.VUE_CLI_SERVICE_CONFIG_PATH) and I need to load environment files after vue.config.js.

might be a nice idea, yes.

Our overall guideline is - all CLI projects should have consistent file structures as much as possible. The CLI is opinionated by nature. This is why we do not provide options for configuring source directory or public directory names. If we add an option for this we essentially need to add options for renaming every possible config file and directory, and that would

  1. make it more work to maintain all these options
  2. increase possibility of edge cases due to different directory names
  3. make Vue CLI projects all look different from one another.

Hello giving second thought of this.

As in my project structure, it's a monorepo that contain backend API and frontend website together.

my-project/
--server/ (node app)
--client/ (vue-cli)

Both may share the same variable, thus it's best if they can refer to the same .env. So my thought is to put the .env file in the root of the project folder:

my-project/
-- server/ (node app)
-- client/ (vue-cli)
-- .env

So, if it's related to the discussion here, can the vue-cli compiler in folder client still able to retrieve the env value from the root directory?

If there's a better suggestion to resolve this, please share ;)

I have the exact same issue as @chenxeed
As a workaround I installed node-env-run as a dev dependency, and now my dev script looks like:

"dev": "nodenv --env ../../.env --exec 'vue-cli-service serve'",

Not ideal but works for now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

b-zee picture b-zee  路  3Comments

DrSensor picture DrSensor  路  3Comments

joshuajohnson814 picture joshuajohnson814  路  3Comments

sanderswang picture sanderswang  路  3Comments

BusyHe picture BusyHe  路  3Comments