8000 docs: add example for build --mode env (#902) · Ddddaemon/vue-cli@9b1d376 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9b1d376

Browse files
kshermanyyx990803
authored andcommitted
docs: add example for build --mode env (vuejs#902)
* docs: add docs on using --mode with build command to use corresponding env vars * Use the arg.mode in the console log "Building for..." message
1 parent e658563 commit 9b1d376

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

docs/env.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ Note that a mode is different from `NODE_ENV`, as a mode can contain multiple en
3737

3838
You can set environment variables only available to a certain mode by postfixing the `.env` file. For example, if you create a file named `.env.development` in your project root, then the variables declared in that file will only be loaded in development mode.
3939

40+
Passing the `--mode` option flag with [build command](https://github.com/vuejs/vue-cli/blob/dev/docs/cli-service.md#build) will use that mode's environment variables in the build. For example, if you want to use development variables in the build command, add this to your package.json scripts:
41+
42+
```
43+
"dev-build": "vue-cli-service build --mode development",
44+
```
45+
4046
### Using Env Variables in Client-side Code
4147

4248
Only variables that start with `VUE_APP_` will be statically embedded into the client bundle with `webpack.DefinePlugin`. You can access them in your application code:

packages/@vue/cli-service/lib/commands/build/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ module.exports = (api, options) => {
4646

4747
log()
4848
if (args.target === 'app') {
49-
logWithSpinner(`Building for production...`)
49+
logWithSpinner(`Building for ${args.mode}...`)
5050
} else {
5151
const buildMode = buildModes[args.target]
5252
if (buildMode) {
53-
logWithSpinner(`Building for production as ${buildMode}...`)
53+
logWithSpinner(`Building for ${args.mode} as ${buildMode}...`)
5454
} else {
5555
throw new Error(`Unknown build target: ${args.target}`)
5656
}

0 commit comments

Comments
 (0)
0