Skip to content

Commit bd57f15

Browse files
authoredFeb 28, 2019
feat: support environment variable expansion (#3534)
1 parent 2de215e commit bd57f15

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed
 

‎docs/guide/mode-and-env.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ FOO=bar
4646
VUE_APP_SECRET=secret
4747
```
4848

49-
For more detailed env parsing rules, please refer to [the documentation of `dotenv`](https://github.com/motdotla/dotenv#rules).
49+
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+).
5050

5151
Loaded variables will become available to all `vue-cli-service` commands, plugins and dependencies.
5252

‎packages/@vue/cli-service/lib/Service.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const merge = require('webpack-merge')
77
const Config = require('webpack-chain')
88
const PluginAPI = require('./PluginAPI')
99
const dotenv = require('dotenv')
10+
const dotenvExpand = require('dotenv-expand')
1011
const defaultsDeep = require('lodash.defaultsdeep')
1112
const { warn, error, isPlugin, loadModule } = require('@vue/cli-shared-utils')
1213

@@ -95,8 +96,9 @@ module.exports = class Service {
9596

9697
const load = path => {
9798
try {
98-
const res = dotenv.config({ path, debug: process.env.DEBUG })
99-
logger(path, res)
99+
const env = dotenv.config({ path, debug: process.env.DEBUG })
100+
dotenvExpand(env)
101+
logger(path, env)
100102
} catch (err) {
101103
// only ignore error if file is not found
102104
if (err.toString().indexOf('ENOENT') < 0) {

‎packages/@vue/cli-service/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"cssnano": "^4.1.10",
4545
"debug": "^4.1.1",
4646
"dotenv": "^6.2.0",
47+
"dotenv-expand": "^4.2.0",
4748
"escape-string-regexp": "^1.0.5",
4849
"file-loader": "^3.0.1",
4950
"fs-extra": "^7.0.1",

‎yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -6211,6 +6211,11 @@ dot-prop@^4.1.0, dot-prop@^4.1.1, dot-prop@^4.2.0:
62116211
dependencies:
62126212
is-obj "^1.0.0"
62136213

6214+
dotenv-expand@^4.2.0:
6215+
version "4.2.0"
6216+
resolved "https://registry.yarnpkg.com/dotenv-expand/-/dotenv-expand-4.2.0.tgz#def1f1ca5d6059d24a766e587942c21106ce1275"
6217+
integrity sha1-3vHxyl1gWdJKdm5YeULCEQbOEnU=
6218+
62146219
dotenv@^6.2.0:
62156220
version "6.2.0"
62166221
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-6.2.0.tgz#941c0410535d942c8becf28d3f357dbd9d476064"

0 commit comments

Comments
 (0)