Skip to content

Commit

Permalink
docs(api): Link webpack CLI Environment options section to guide
Browse files Browse the repository at this point in the history
(squash me)
  • Loading branch information
grisanu committed Aug 26, 2017
1 parent 5881750 commit 0030d30
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/content/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 6 additions & 6 deletions src/content/guides/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**

Expand Down Expand Up @@ -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.

0 comments on commit 0030d30

Please sign in to comment.