Skip to content
This repository has been archived by the owner on Dec 6, 2021. It is now read-only.

Commit

Permalink
add define
Browse files Browse the repository at this point in the history
  • Loading branch information
egoist committed Feb 16, 2017
1 parent 6229dab commit 7aa28d2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* [Webpack](#webpack)
* [Custom HTML output](#custom-html-output)
* [Custom output filename](#custom-output-filename)
* [Define constants at compile time](#define-constants-at-compile-time)
* [Proxy API request](#proxy-api-request)
* [Dev server](#dev-server)
+ [port](#port)
Expand Down Expand Up @@ -273,6 +274,28 @@ module.exports = {

[⬆ back to top](#vbuild)

### Define constants at compile time

`define` is a short-hand to add webpack's [DefinePlugin](https://webpack.js.org/plugins/define-plugin/) for settings global constants which can be configured at compile time.

```js
module.exports = options => ({
define: {
__DEV__: JSON.stringify(options.dev)
}
})
```

Then use it in your app code:

```js
if (__DEV__) {
// perform something only in development mode a.k.a `--dev`
}
```

The default constants we add is `process.env.NODE_ENV`.

### Proxy API request

To tell the development server to serve any `/api/*` request to your API server in development, use the `proxy` options:
Expand Down
4 changes: 2 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ function start(cliOptions) { // eslint-disable-line complexity
console.log()
}
}),
new webpack.DefinePlugin({
new webpack.DefinePlugin(Object.assign({
'process.env.NODE_ENV': JSON.stringify(options.dev ? 'development' : 'production')
}),
}, options.define)),
new webpack.LoaderOptionsPlugin({
minimize: !options.dev,
options: {
Expand Down

0 comments on commit 7aa28d2

Please sign in to comment.