Skip to content

Commit 62e2868

Browse files
Ray FossAkryum
authored andcommitted
docs: Include Tip about computed env vars (vuejs#1780)
* Include tip about computed env vars I'm personally using this frivolously in my own footer ``` // vue.config.js const revision = require('child_process').execSync('git rev-parse HEAD').toString().trim() const pjson = require('./package.json') process.env.VUE_APP_COMMIT = `"${revision}"` process.env.VUE_APP_VERSION = `"${pjson.version}"` module.exports = {} ``` ``` <template> <footer> <span>v{{ version }} ({{ commit }})</span> </footer> </template> <script> export default { data: function () { return { version: process.env.VUE_APP_VERSION, commit: process.env.VUE_APP_COMMIT } } } ``` # Validation - I'm using this. - The inline require doesn't cause lint issues on vue-cli v3 config files. I did a full builds to check. * tip format match * tip format * tip, format * markdown formatting conflicts with es6 templates Also, quotes, optional now. interesting. I tried it. * remove template stray * filenames are not proper english grammar, yet
1 parent 78174dc commit 62e2868

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

docs/guide/mode-and-env.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ In addition to `VUE_APP_*` variables, there are also two special variables that
7474

7575
All resolved env variables will be available inside `public/index.html` as discussed in [HTML - Interpolation](./html-and-static-assets.md#interpolation).
7676

77+
::: tip
78+
You can have computed env vars in your `vue.config.js` file. They still need to be prefixed with `VUE_APP_`. This is useful for version info `process.env.VUE_APP_VERSION = require('./package.json').version`
79+
:::
80+
7781
## Local Only Variables
7882

7983
Sometimes you might have env variables that should not be committed into the codebase, especially if your project is hosted in a public repository. In that case you should use an `.env.local` file instead. Local env files are ignored in `.gitignore` by default.

0 commit comments

Comments
 (0)