mirror of
https://github.com/vuejs/vue-cli.git
synced 2026-03-13 12:40:18 -05:00
feat: support environment variable expansion (#3534)
This commit is contained in:
@@ -46,7 +46,7 @@ FOO=bar
|
||||
VUE_APP_SECRET=secret
|
||||
```
|
||||
|
||||
For more detailed env parsing rules, please refer to [the documentation of `dotenv`](https://github.com/motdotla/dotenv#rules).
|
||||
For more detailed env parsing rules, please refer to [the documentation of `dotenv`](https://github.com/motdotla/dotenv#rules). We also use [dotenv-expand](https://github.com/motdotla/dotenv-expand) for variable expansion (available in Vue CLI 3.5+).
|
||||
|
||||
Loaded variables will become available to all `vue-cli-service` commands, plugins and dependencies.
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ const merge = require('webpack-merge')
|
||||
const Config = require('webpack-chain')
|
||||
const PluginAPI = require('./PluginAPI')
|
||||
const dotenv = require('dotenv')
|
||||
const dotenvExpand = require('dotenv-expand')
|
||||
const defaultsDeep = require('lodash.defaultsdeep')
|
||||
const { warn, error, isPlugin, loadModule } = require('@vue/cli-shared-utils')
|
||||
|
||||
@@ -95,8 +96,9 @@ module.exports = class Service {
|
||||
|
||||
const load = path => {
|
||||
try {
|
||||
const res = dotenv.config({ path, debug: process.env.DEBUG })
|
||||
logger(path, res)
|
||||
const env = dotenv.config({ path, debug: process.env.DEBUG })
|
||||
dotenvExpand(env)
|
||||
logger(path, env)
|
||||
} catch (err) {
|
||||
// only ignore error if file is not found
|
||||
if (err.toString().indexOf('ENOENT') < 0) {
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
"cssnano": "^4.1.10",
|
||||
"debug": "^4.1.1",
|
||||
"dotenv": "^6.2.0",
|
||||
"dotenv-expand": "^4.2.0",
|
||||
"escape-string-regexp": "^1.0.5",
|
||||
"file-loader": "^3.0.1",
|
||||
"fs-extra": "^7.0.1",
|
||||
|
||||
@@ -6211,6 +6211,11 @@ dot-prop@^4.1.0, dot-prop@^4.1.1, dot-prop@^4.2.0:
|
||||
dependencies:
|
||||
is-obj "^1.0.0"
|
||||
|
||||
dotenv-expand@^4.2.0:
|
||||
version "4.2.0"
|
||||
resolved "https://registry.yarnpkg.com/dotenv-expand/-/dotenv-expand-4.2.0.tgz#def1f1ca5d6059d24a766e587942c21106ce1275"
|
||||
integrity sha1-3vHxyl1gWdJKdm5YeULCEQbOEnU=
|
||||
|
||||
dotenv@^6.2.0:
|
||||
version "6.2.0"
|
||||
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-6.2.0.tgz#941c0410535d942c8becf28d3f357dbd9d476064"
|
||||
|
||||
Reference in New Issue
Block a user