Skip to content

Commit 0c96dd5

Browse files
EugeneHlushkoTheDutchCoder
authored andcommitted
docs(Concepts): update concepts page for v4 (#1883)
This updates the Concepts page to facilitate webpack v4's options and changes.
1 parent 38faec2 commit 0c96dd5

File tree

3 files changed

+84
-11
lines changed

3 files changed

+84
-11
lines changed

src/content/concepts/index.md

Lines changed: 17 additions & 11 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
@@ -31,7 +32,7 @@ An **entry point** indicates which module webpack should use to begin building o
3132

3233
Every dependency is then processed and outputted into files called *bundles*, which we'll discuss more in the next section.
3334

34-
You can specify an entry point (or multiple entry points) by configuring the `entry` property in the [webpack configuration](/configuration).
35+
You can specify an entry point (or multiple entry points) by configuring the `entry` property in the [webpack configuration](/configuration). It defaults to `./src`.
3536

3637
Here's the simplest example of an `entry` configuration:
3738

@@ -48,7 +49,7 @@ T> You can configure the `entry` property in various ways depending the needs of
4849

4950
## Output
5051

51-
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:
52+
The **output** property tells webpack where to emit the *bundles* it creates and how to name these files and defaults to `./dist`. You can configure this part of the process by specifying an `output` field in your configuration:
5253

5354
__webpack.config.js__
5455

@@ -90,9 +91,7 @@ __webpack.config.js__
9091
const path = require('path');
9192

9293
const config = {
93-
entry: './path/to/my/entry/file.js',
9494
output: {
95-
path: path.resolve(__dirname, 'dist'),
9695
filename: 'my-first-webpack.bundle.js'
9796
},
9897
module: {
@@ -127,14 +126,8 @@ In order to use a plugin, you need to `require()` it and add it to the `plugins`
127126
```javascript
128127
const HtmlWebpackPlugin = require('html-webpack-plugin'); //installed via npm
129128
const webpack = require('webpack'); //to access built-in plugins
130-
const path = require('path');
131129

132130
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-
},
138131
module: {
139132
rules: [
140133
{ test: /\.txt$/, use: 'raw-loader' }
@@ -154,3 +147,16 @@ There are many plugins that webpack provides out of the box! Check out our [list
154147
Using plugins in your webpack config is straightforward - however, there are many use cases that are worth further exploration.
155148

156149
[Learn more!](/concepts/plugins)
150+
151+
152+
## Mode
153+
154+
By setting the `mode` parameter to either `development` or `production`, you can enable webpack's built-in optimizations that correspond with the selected mode.
155+
156+
```javascript
157+
module.exports = {
158+
mode: 'production'
159+
};
160+
```
161+
162+
[Learn more!](/concepts/mode)

src/content/concepts/mode.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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`
11+
12+
## Usage
13+
14+
Just provide the `mode` option in the config:
15+
16+
```javascript
17+
module.exports = {
18+
mode: 'production'
19+
};
20+
```
21+
22+
23+
or pass it as a cli argument:
24+
25+
```bash
26+
webpack --mode=production
27+
```
28+
29+
The following string values are supported:
30+
31+
Option | Description
32+
--------------------- | -----------------------
33+
`development` | Provides `process.env.NODE_ENV` with value `development`. Enables `NamedModulesPlugin`.
34+
`production` | Provides `process.env.NODE_ENV` with value `production`. Enables `UglifyJsPlugin`, `ModuleConcatenationPlugin` and `NoEmitOnErrorsPlugin`.
35+
36+
37+
### Mode: development
38+
39+
40+
```diff
41+
// webpack.production.config.js
42+
module.exports = {
43+
+ mode: 'development'
44+
- plugins: [
45+
- new webpack.NamedModulesPlugin(),
46+
- new webpack.DefinePlugin({ "process.env.NODE_ENV": JSON.stringify("development") }),
47+
- ]
48+
}
49+
```
50+
51+
52+
### Mode: production
53+
54+
55+
```diff
56+
// webpack.production.config.js
57+
module.exports = {
58+
+ mode: 'production',
59+
- plugins: [
60+
- new UglifyJsPlugin(/* ... */),
61+
- new webpack.DefinePlugin({ "process.env.NODE_ENV": JSON.stringify("production") }),
62+
- new webpack.optimize.ModuleConcatenationPlugin(),
63+
- new webpack.NoEmitOnErrorsPlugin()
64+
- ]
65+
}
66+
```

src/content/guides/getting-started.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ We also need to adjust our `package.json` file in order to make sure we mark our
7777
T> If you want to learn more about the inner workings of `package.json`, then we recommend reading the [npm documentation](https://docs.npmjs.com/files/package.json).
7878

7979
__package.json__
80+
8081
``` diff
8182
{
8283
"name": "webpack-demo",

0 commit comments

Comments
 (0)