Skip to content

Commit 6d83752

Browse files
committed
docs(concepts) Update concepts and explain mode option
1 parent 38faec2 commit 6d83752

File tree

2 files changed

+77
-9
lines changed

2 files changed

+77
-9
lines changed

src/content/concepts/index.md

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ contributors:
99
- jimrfenner
1010
- TheDutchCoder
1111
- adambraimbridge
12+
- EugeneHlushko
1213
---
1314

1415
At its core, *webpack* is a _static module bundler_ for modern JavaScript applications. When webpack processes your application, it recursively builds a _dependency graph_ that includes every module your application needs, then packages all of those modules into one or more _bundles_.
1516

1617
T> Learn more about JavaScript modules and webpack modules [here](/concepts/modules).
1718

18-
It is [incredibly configurable](/configuration), but to get started you only need to understand four **Core Concepts**:
19+
Since v4.0.0 webpack does not require a configuration file. Nevertheless, it is [incredibly configurable](/configuration). To get started you only need to understand four **Core Concepts**:
1920

2021
- Entry
2122
- Output
@@ -33,6 +34,8 @@ Every dependency is then processed and outputted into files called *bundles*, wh
3334

3435
You can specify an entry point (or multiple entry points) by configuring the `entry` property in the [webpack configuration](/configuration).
3536

37+
T> `entry` defaults to `./src`
38+
3639
Here's the simplest example of an `entry` configuration:
3740

3841
__webpack.config.js__
@@ -50,6 +53,8 @@ T> You can configure the `entry` property in various ways depending the needs of
5053

5154
The **output** property tells webpack where to emit the *bundles* it creates and how to name these files. You can configure this part of the process by specifying an `output` field in your configuration:
5255

56+
T> `output.path` defaults to `./dist`
57+
5358
__webpack.config.js__
5459

5560
```javascript
@@ -90,9 +95,7 @@ __webpack.config.js__
9095
const path = require('path');
9196

9297
const config = {
93-
entry: './path/to/my/entry/file.js',
9498
output: {
95-
path: path.resolve(__dirname, 'dist'),
9699
filename: 'my-first-webpack.bundle.js'
97100
},
98101
module: {
@@ -127,14 +130,8 @@ In order to use a plugin, you need to `require()` it and add it to the `plugins`
127130
```javascript
128131
const HtmlWebpackPlugin = require('html-webpack-plugin'); //installed via npm
129132
const webpack = require('webpack'); //to access built-in plugins
130-
const path = require('path');
131133

132134
const config = {
133-
entry: './path/to/my/entry/file.js',
134-
output: {
135-
path: path.resolve(__dirname, 'dist'),
136-
filename: 'my-first-webpack.bundle.js'
137-
},
138135
module: {
139136
rules: [
140137
{ test: /\.txt$/, use: 'raw-loader' }
@@ -154,3 +151,16 @@ There are many plugins that webpack provides out of the box! Check out our [list
154151
Using plugins in your webpack config is straightforward - however, there are many use cases that are worth further exploration.
155152

156153
[Learn more!](/concepts/plugins)
154+
155+
156+
## Mode
157+
158+
By choosing between `development` and `production` **mode** you can enable webpack's automatic optimizations according to selected option.
159+
160+
```javascript
161+
module.exports = {
162+
mode: 'production'
163+
};
164+
```
165+
166+
[Learn more!](/concepts/mode)

src/content/concepts/mode.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
title: Mode
3+
sort: 4
4+
contributors:
5+
- EugeneHlushko
6+
---
7+
8+
Providing the `mode` configuration option tells webpack to use its built-in optimizations accordingly.
9+
10+
`string` (development | production)
11+
12+
13+
## Usage
14+
15+
Just provide the `mode` option in the config:
16+
17+
```javascript
18+
module.exports = {
19+
mode: 'production'
20+
};
21+
```
22+
23+
or pass it as a cli argument:
24+
25+
```bash
26+
webpack --mode=production
27+
```
28+
29+
30+
## Mode: development
31+
32+
33+
```diff
34+
// webpack.production.config.js
35+
module.exports = {
36+
+ mode: 'development'
37+
- plugins: [
38+
- new webpack.NamedModulesPlugin(),
39+
- new webpack.DefinePlugin({ "process.env.NODE_ENV": JSON.stringify("development") }),
40+
- ]
41+
}
42+
```
43+
44+
## Mode: production
45+
46+
47+
```diff
48+
// webpack.production.config.js
49+
module.exports = {
50+
+ mode: 'production',
51+
- plugins: [
52+
- new UglifyJsPlugin(/* ... */),
53+
- new webpack.DefinePlugin({ "process.env.NODE_ENV": JSON.stringify("production") }),
54+
- new webpack.optimize.ModuleConcatenationPlugin(),
55+
- new webpack.NoEmitOnErrorsPlugin()
56+
- ]
57+
}
58+
```

0 commit comments

Comments
 (0)