Skip to content

Commit 1794982

Browse files
EugeneHlushkomontogeek
authored andcommitted
docs(guides) Finish updating guides: production (webpack#2400)
* docs(guides) update production guide to v4 * misc(core) formatting in package.json
1 parent 473a6c4 commit 1794982

File tree

2 files changed

+38
-45
lines changed

2 files changed

+38
-45
lines changed

package.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,12 @@
4545
}
4646
},
4747
"lint-staged": {
48-
"*.{js,jsx,md}": ["npm run lint:js"],
49-
"*.md": ["npm run lint:markdown"]
48+
"*.{js,jsx,md}": [
49+
"npm run lint:js"
50+
],
51+
"*.md": [
52+
"npm run lint:markdown"
53+
]
5054
},
5155
"devDependencies": {
5256
"alex": "^4.1.0",

src/content/guides/production.md

+32-43
Original file line numberDiff line numberDiff line change
@@ -148,42 +148,6 @@ __package.json__
148148
Feel free to run those scripts and see how the output changes as we continue adding to our _production_ configuration.
149149

150150

151-
## Minification
152-
153-
Note that while the [`UglifyJSPlugin`](/plugins/uglifyjs-webpack-plugin) is a great place to start for minification, there are other options out there. Here are a few more popular ones:
154-
155-
- [`BabelMinifyWebpackPlugin`](https://github.com/webpack-contrib/babel-minify-webpack-plugin)
156-
- [`ClosureCompilerPlugin`](https://github.com/roman01la/webpack-closure-compiler)
157-
158-
If you decide to try another minification plugin, just make sure your new choice also drops dead code as described in the [tree shaking](/guides/tree-shaking) guide.
159-
160-
161-
## Source Mapping
162-
163-
We encourage you to have source maps enabled in production, as they are useful for debugging as well as running benchmark tests. That said, you should choose one with a fairly quick build speed that's recommended for production use (see [`devtool`](/configuration/devtool)). For this guide, we'll use the `source-map` option in _production_ as opposed to the `inline-source-map` we used in _development_:
164-
165-
__webpack.prod.js__
166-
167-
``` diff
168-
const merge = require('webpack-merge');
169-
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
170-
const common = require('./webpack.common.js');
171-
172-
module.exports = merge(common, {
173-
mode: 'production',
174-
+ devtool: 'source-map',
175-
plugins: [
176-
- new UglifyJSPlugin()
177-
+ new UglifyJSPlugin({
178-
+ sourceMap: true
179-
+ })
180-
]
181-
});
182-
```
183-
184-
T> Avoid `inline-***` and `eval-***` use in production as they can increase bundle size and reduce the overall performance.
185-
186-
187151
## Specify the Mode
188152

189153
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:
@@ -192,17 +156,11 @@ __webpack.prod.js__
192156

193157
``` diff
194158
const merge = require('webpack-merge');
195-
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
196159
const common = require('./webpack.common.js');
197160

198161
module.exports = merge(common, {
199162
mode: 'production',
200-
devtool: 'source-map',
201-
plugins: [
202-
new UglifyJSPlugin({
203-
sourceMap: true
204-
})
205-
]
163+
devtool: 'source-map'
206164
});
207165
```
208166

@@ -234,6 +192,37 @@ __src/index.js__
234192
```
235193

236194

195+
## Minification
196+
197+
webpack v4+ will minify your code by default in [`production mode`](/concepts/mode/#mode-production).
198+
199+
Note that while the [`UglifyJSPlugin`](/plugins/uglifyjs-webpack-plugin) is a great place to start for minification and being used by default, there are other options out there. Here are a few more popular ones:
200+
201+
- [`BabelMinifyWebpackPlugin`](https://github.com/webpack-contrib/babel-minify-webpack-plugin)
202+
- [`ClosureCompilerPlugin`](https://github.com/roman01la/webpack-closure-compiler)
203+
204+
If you decide to try another minification plugin, just make sure your new choice also drops dead code as described in the [tree shaking](/guides/tree-shaking) guide and provide it as the [`optimization.minimizer`](/configuration/optimization/#optimization-minimizer).
205+
206+
207+
## Source Mapping
208+
209+
We encourage you to have source maps enabled in production, as they are useful for debugging as well as running benchmark tests. That said, you should choose one with a fairly quick build speed that's recommended for production use (see [`devtool`](/configuration/devtool)). For this guide, we'll use the `source-map` option in _production_ as opposed to the `inline-source-map` we used in _development_:
210+
211+
__webpack.prod.js__
212+
213+
``` diff
214+
const merge = require('webpack-merge');
215+
const common = require('./webpack.common.js');
216+
217+
module.exports = merge(common, {
218+
mode: 'production',
219+
+ devtool: 'source-map'
220+
});
221+
```
222+
223+
T> Avoid `inline-***` and `eval-***` use in production as they can increase bundle size and reduce the overall performance.
224+
225+
237226
## Minimize CSS
238227

239228
It is crucial to minimize your CSS on production, please see [Minimizing for Production](/plugins/mini-css-extract-plugin/#minimizing-for-production) section.

0 commit comments

Comments
 (0)