You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/concepts/index.md
+17-11Lines changed: 17 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -9,13 +9,14 @@ contributors:
9
9
- jimrfenner
10
10
- TheDutchCoder
11
11
- adambraimbridge
12
+
- EugeneHlushko
12
13
---
13
14
14
15
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_.
15
16
16
17
T> Learn more about JavaScript modules and webpack modules [here](/concepts/modules).
17
18
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**:
19
20
20
21
- Entry
21
22
- Output
@@ -31,7 +32,7 @@ An **entry point** indicates which module webpack should use to begin building o
31
32
32
33
Every dependency is then processed and outputted into files called *bundles*, which we'll discuss more in the next section.
33
34
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`.
35
36
36
37
Here's the simplest example of an `entry` configuration:
37
38
@@ -48,7 +49,7 @@ T> You can configure the `entry` property in various ways depending the needs of
48
49
49
50
## Output
50
51
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:
52
53
53
54
__webpack.config.js__
54
55
@@ -90,9 +91,7 @@ __webpack.config.js__
90
91
constpath=require('path');
91
92
92
93
constconfig= {
93
-
entry:'./path/to/my/entry/file.js',
94
94
output: {
95
-
path:path.resolve(__dirname, 'dist'),
96
95
filename:'my-first-webpack.bundle.js'
97
96
},
98
97
module: {
@@ -127,14 +126,8 @@ In order to use a plugin, you need to `require()` it and add it to the `plugins`
127
126
```javascript
128
127
constHtmlWebpackPlugin=require('html-webpack-plugin'); //installed via npm
@@ -154,3 +147,16 @@ There are many plugins that webpack provides out of the box! Check out our [list
154
147
Using plugins in your webpack config is straightforward - however, there are many use cases that are worth further exploration.
155
148
156
149
[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.
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(),
Copy file name to clipboardExpand all lines: src/content/guides/getting-started.md
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -77,6 +77,7 @@ We also need to adjust our `package.json` file in order to make sure we mark our
77
77
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).
0 commit comments