Skip to content

Commit 473a6c4

Browse files
SevenOutmanmontogeek
authored andcommitted
docs(guides) Update production guide, fix webpack#2387 (webpack#2388)
Add explanation to [Specify the Environment](https://webpack.js.org/guides/production/#specify-the-environment) section in production guide, which is no longer effective with webpack v4. See advice here webpack#2387. P.S. I think it's better adding an instruction than removing the whole section, for there're users of previous major versions. If there's a separate branch and url for v3 docs, I'll add changes and remove the whole section in master.
1 parent 26c25ad commit 473a6c4

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/content/guides/production.md

+4-8
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ contributors:
1616
- kelset
1717
- xgirma
1818
- mehrdaad
19+
- SevenOutman
1920
---
2021

2122
In this guide we'll dive into some of the best practices and utilities for building a production site or application.
@@ -183,14 +184,13 @@ __webpack.prod.js__
183184
T> Avoid `inline-***` and `eval-***` use in production as they can increase bundle size and reduce the overall performance.
184185

185186

186-
## Specify the Environment
187+
## Specify the Mode
187188

188-
Many libraries will key off the `process.env.NODE_ENV` variable to determine what should be included in the library. For example, when not in _production_ some libraries may add additional logging and testing to make debugging easier. However, with `process.env.NODE_ENV === 'production'` they might drop or add significant portions of code to optimize how things run for your actual users. We can use webpack's built in [`DefinePlugin`](/plugins/define-plugin) to define this variable for all our dependencies:
189+
Many libraries will key off the `process.env.NODE_ENV` variable to determine what should be included in the library. For example, when not in _production_ some libraries may add additional logging and testing to make debugging easier. However, with `process.env.NODE_ENV === 'production'` they might drop or add significant portions of code to optimize how things run for your actual users. Since webpack v4, specifying [`mode`](/concepts/mode/) automatically configures [`DefinePlugin`](/plugins/define-plugin) for you:
189190

190191
__webpack.prod.js__
191192

192193
``` diff
193-
+ const webpack = require('webpack');
194194
const merge = require('webpack-merge');
195195
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
196196
const common = require('./webpack.common.js');
@@ -201,11 +201,7 @@ __webpack.prod.js__
201201
plugins: [
202202
new UglifyJSPlugin({
203203
sourceMap: true
204-
- })
205-
+ }),
206-
+ new webpack.DefinePlugin({
207-
+ 'process.env.NODE_ENV': JSON.stringify('production')
208-
+ })
204+
})
209205
]
210206
});
211207
```

0 commit comments

Comments
 (0)