docs: Include Tip about computed env vars (#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
This commit is contained in:
Ray Foss
2018-07-10 18:28:04 -05:00
committed by Guillaume Chau
parent 78174dc5e8
commit 62e2868007

View File

@@ -74,6 +74,10 @@ In addition to `VUE_APP_*` variables, there are also two special variables that
All resolved env variables will be available inside `public/index.html` as discussed in [HTML - Interpolation](./html-and-static-assets.md#interpolation).
::: tip
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`
:::
## Local Only Variables
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.