diff --git a/src/content/api/cli.md b/src/content/api/cli.md index d5e496cff412..a7059f99a850 100644 --- a/src/content/api/cli.md +++ b/src/content/api/cli.md @@ -139,6 +139,8 @@ The `--env` argument accepts various syntaxes: | webpack --env.prod --env.min | `{ prod: true, min: true }` | | webpack --env.prod --env min | `[{ prod: true }, "min"]` | +T> See this [environment variables](/guides/environment-variables) guide for more information. + ### Output Options This set of options allows you to manipulate certain [output](/configuration/output) parameters of your build. diff --git a/src/content/guides/environment-variables.md b/src/content/guides/environment-variables.md index a43147d8a1e1..5fe3ac9ffc81 100644 --- a/src/content/guides/environment-variables.md +++ b/src/content/guides/environment-variables.md @@ -9,15 +9,17 @@ related: url: https://blog.flennik.com/the-fine-art-of-the-webpack-2-config-dc4d19d7f172#d60a --- -To disambiguate in your `webpack.config.js` between [development](/guides/development) and [production builds](/guides/production), you may use environment variables. +To disambiguate between [development](/guides/development) and [production](/guides/production) builds in your `webpack.config.js`, you may want to use environment variables. -The webpack command line option `--env` allows you to pass in as many environment variables as you like, such as `--env.production` or `--env.NODE_ENV=local`. (`NODE_ENV` is commonly used as de-facto standard. See [here](https://dzone.com/articles/what-you-should-know-about-node-env)). These variables will be made accesible in the webpack config. +The webpack command line [environment option](/api/cli/#environment-options), `--env` allows you to pass in as many environment variables as you would like. Environment variables will be made accesible in your `webpack.config.js`. For example, `--env.production` or `--env.NODE_ENV=local` (`NODE_ENV` is conventionally used to define the environment type, see [here](https://dzone.com/articles/what-you-should-know-about-node-env).) -``` +```shell >> webpack --env.NODE_ENV=local --env.production --progress ``` -There is, however a change that you will have to make to your webpack config. Typically, in your webpack config `module.exports` points to the configuration object. To use the `env` variable, you must change `module.exports` to be a function: +T> Setting up your `env` variable without assignment, `--env.prduction` sets `env.prduction` to `true` by default. See the [webpack CLI](/api/cli/#environment-options) documentation for more information. + +Howeve, there is a change that you will have to make to your `webpack.config.js`. Typically, in your webpack configuration file `module.exports` points to the configuration object. To use the `env` variable, you must change `module.exports` to be a function: **webpack.config.js** @@ -46,5 +48,3 @@ There is, however a change that you will have to make to your webpack config. Ty + } + } ``` - -**NOTE:** Setting up your `env` varialbe without assignment, `--env.prduction` sets `env.prduction` to `true` by default.