Skip to content

Commit d2cf474

Browse files
committed
Merge branch 'master' into rebuild
2 parents 748db04 + 60c38ae commit d2cf474

25 files changed

+308
-160
lines changed

src/content/api/cli.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ contributors:
66
- simon04
77
- tbroadley
88
- chenxsan
9+
- rencire
910
- madhavarshney
1011
related:
1112
- title: Analyzing Build Statistics
@@ -68,7 +69,7 @@ If your project structure is as follows -
6869
```
6970

7071
```bash
71-
webpack ./src/index.js dist/bundle.js
72+
webpack src/index.js -o dist/bundle.js
7273
```
7374

7475
This will bundle your source code with entry as `index.js` and the output bundle file will have a path of `dist` and the filename will be `bundle.js`

src/content/api/compiler-hooks.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,6 @@ Can return true/false at this point
191191
Parameters: `compilation`
192192

193193

194-
### `needAdditionalPass`
195-
196-
`SyncBailHook`
197-
198-
...
199-
200-
201194
### `emit`
202195

203196
`AsyncSeriesHook`

src/content/api/module-methods.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ sort: 3
55
contributors:
66
- skipjack
77
- sokra
8+
- fadysamirsadek
89
- byzyk
910
related:
1011
- title: CommonJS Wikipedia
@@ -74,14 +75,14 @@ W> This feature relies on [`Promise`](https://developer.mozilla.org/en-US/docs/W
7475
The spec for `import` doesn't allow control over the chunk's name or other properties as "chunks" are only a concept within webpack. Luckily webpack allows some special parameters via comments so as to not break the spec:
7576

7677
``` js
77-
// single target
78+
// Single target
7879
import(
7980
/* webpackChunkName: "my-chunk-name" */
8081
/* webpackMode: "lazy" */
8182
'module'
8283
);
8384

84-
// multiple possible targets
85+
// Multiple possible targets
8586
import(
8687
/* webpackInclude: /\.json$/ */
8788
/* webpackExclude: /\.noimport\.json$/ */
@@ -91,6 +92,14 @@ import(
9192
);
9293
```
9394

95+
```js
96+
import(/* webpackIgnore: true */ 'ignored-module.js');
97+
```
98+
99+
`webpackIgnore`: Disables dynamic import parsing when set to `true`.
100+
101+
W> Note that setting `webpackIgnore` to `true` opts out of code splitting.
102+
94103
`webpackChunkName`: A name for the new chunk. Since webpack 2.6.0, the placeholders `[index]` and `[request]` are supported within the given string to an incremented number or the actual resolved filename respectively.
95104

96105
`webpackMode`: Since webpack 2.6.0, different modes for resolving dynamic imports can be specified. The following options are supported:

src/content/concepts/entry-points.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module.exports = {
3434

3535
T> **What happens when you pass an array to `entry`?** Passing an array of file paths to the `entry` property creates what is known as a **"multi-main entry"**. This is useful when you would like to inject multiple dependent files together and graph their dependencies into one "chunk".
3636

37-
This is a great choice when you are looking to quickly setup a webpack configuration for an application or tool with one entry point (IE: a library). However, there is not much flexibility in extending or scaling your configuration with this syntax.
37+
This is a great choice when you are looking to quickly setup a webpack configuration for an application or tool with one entry point (i.e., a library). However, there is not much flexibility in extending or scaling your configuration with this syntax.
3838

3939

4040
## Object Syntax
@@ -75,7 +75,7 @@ module.exports = {
7575
};
7676
```
7777

78-
**What does this do?** At face value this tells webpack to create dependency graphs starting at both `app.js` and `vendors.js`. These graphs are completely separate and independent of each other (there will be a webpack bootstrap in each bundle). This is commonly seen with single page applications which have only one entry point (excluding vendors).
78+
**What does this do?** At face value, this tells webpack to create dependency graphs starting at both `app.js` and `vendors.js`. These graphs are completely separate and independent of each other (there will be a webpack bootstrap in each bundle). This is commonly seen with single page applications which have only one entry point (excluding vendors).
7979

8080
**Why?** This setup allows you to leverage `CommonsChunkPlugin` and extract any vendor references from your app bundle into your vendor bundle, replacing them with `__webpack_require__()` calls. If there is no vendor code in your application bundle, then you can achieve a common pattern in webpack known as [long-term vendor-caching](/guides/caching).
8181

src/content/concepts/index.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ For a better understanding of the ideas behind module bundlers and how they work
4040

4141
## Entry
4242

43-
An **entry point** indicates which module webpack should use to begin building out its internal *dependency graph*, webpack will figure out which other modules and libraries that entry point depends on (directly and indirectly).
43+
An **entry point** indicates which module webpack should use to begin building out its internal *dependency graph*. webpack will figure out which other modules and libraries that entry point depends on (directly and indirectly).
4444

4545
By default its value is `./src/index.js`, but you can specify a different (or multiple entry points) by configuring the **entry** property in the [webpack configuration](/configuration). For example:
4646

@@ -57,7 +57,7 @@ T> Learn more in the [entry points](/concepts/entry-points) section.
5757

5858
## Output
5959

60-
The **output** property tells webpack where to emit the *bundles* it creates and how to name these files, it defaults to `./dist/main.js` for the main output file and to the `./dist` folder for any other generated file.
60+
The **output** property tells webpack where to emit the *bundles* it creates and how to name these files. It defaults to `./dist/main.js` for the main output file and to the `./dist` folder for any other generated file.
6161

6262
You can configure this part of the process by specifying an `output` field in your configuration:
6363

@@ -82,7 +82,7 @@ T> The `output` property has [many more configurable features](/configuration/ou
8282

8383
## Loaders
8484

85-
Out of the box, webpack only understands JavaScript files. **Loaders** allow webpack to process other types of files and converting them into valid [modules](/concepts/modules) that can be consumed by your application and added to the dependency graph.
85+
Out of the box, webpack only understands JavaScript files. **Loaders** allow webpack to process other types of files and convert them into valid [modules](/concepts/modules) that can be consumed by your application and added to the dependency graph.
8686

8787
W> Note that the ability to `import` any type of module, e.g. `.css` files, is a feature specific to webpack and may not be supported by other bundlers or task runners. We feel this extension of the language is warranted as it allows developers to build a more accurate dependency graph.
8888

@@ -119,7 +119,7 @@ You can check further customization when including loaders in the [loaders secti
119119

120120
## Plugins
121121

122-
While loaders are used to transform certain types of modules, plugins can be leveraged to perform a wider range of tasks like bundle optimization, assets management and injection of environment variables.
122+
While loaders are used to transform certain types of modules, plugins can be leveraged to perform a wider range of tasks like bundle optimization, asset management and injection of environment variables.
123123

124124
T> Check out the [plugin interface](/api/plugins) and how to use it to extend webpacks capabilities.
125125

@@ -143,11 +143,11 @@ module.exports = {
143143
};
144144
```
145145

146-
In the example above, the `html-webpack-plugin` generates an html file for your application injecting automatically all your generated bundles.
146+
In the example above, the `html-webpack-plugin` generates an HTML file for your application by injecting automatically all your generated bundles.
147147

148148
T> There are many plugins that webpack provides out of the box! Check out the [list of plugins](/plugins).
149149

150-
Using plugins in your webpack config is straightforward - however, there are many use cases that are worth further exploration, [learn more about them here](/concepts/plugins).
150+
Using plugins in your webpack config is straightforward - however, there are many use cases that are worth further exploration. [Learn more about them here](/concepts/plugins).
151151

152152

153153
## Mode

src/content/concepts/loaders.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ contributors:
1212
- byzyk
1313
---
1414

15-
Loaders are transformations that are applied on the source code of a module. They allow you to pre-process files as you `import` or “load” them. Thus, loaders are kind of like “tasks” in other build tools, and provide a powerful way to handle front-end build steps. Loaders can transform files from a different language (like TypeScript) to JavaScript, or inline images as data URLs. Loaders even allow you to do things like `import` CSS files directly from your JavaScript modules!
15+
Loaders are transformations that are applied on the source code of a module. They allow you to pre-process files as you `import` or “load” them. Thus, loaders are kind of like “tasks” in other build tools and provide a powerful way to handle front-end build steps. Loaders can transform files from a different language (like TypeScript) to JavaScript or inline images as data URLs. Loaders even allow you to do things like `import` CSS files directly from your JavaScript modules!
1616

1717

1818
## Example
@@ -52,7 +52,9 @@ There are three ways to use loaders in your application:
5252
### Configuration
5353

5454
[`module.rules`](/configuration/module/#module-rules) allows you to specify several loaders within your webpack configuration.
55-
This is a concise way to display loaders, and helps to maintain clean code. It also offers you a full overview of each respective loader:
55+
This is a concise way to display loaders, and helps to maintain clean code. It also offers you a full overview of each respective loader.
56+
57+
Loaders are evaluated/executed from right to left. In the example below execution starts with sass-loader, continues with css-loader and finally ends with style-loader. See ["Loader Features"](/concepts/loaders/#loader-features) for more information about loaders order.
5658

5759
```js-with-links-with-details
5860
module.exports = {
@@ -67,7 +69,8 @@ module.exports = {
6769
options: {
6870
modules: true
6971
}
70-
}
72+
},
73+
{ loader: ['sass-loader'](/loaders/sass-loader) }
7174
]
7275
}
7376
]

src/content/concepts/mode.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ module.exports = {
8888
}
8989
```
9090

91-
If you want to change the behavior according the **mode** variable inside the *webpack.config.js* you have to export a function instead of an object:
91+
If you want to change the behavior according to the **mode** variable inside the *webpack.config.js*, you have to export a function instead of an object:
9292

9393
```javascript
9494
var config = {

src/content/concepts/output.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,21 @@ Configuring the `output` configuration options tells webpack how to write the co
1313

1414
## Usage
1515

16-
The minimum requirements for the `output` property in your webpack config is to set its value to an object including the following two things:
16+
The minimum requirements for the `output` property in your webpack config is to set its value to an object including the following thing:
1717

1818
- A `filename` to use for the output file(s).
19-
- An absolute `path` to your preferred output directory.
2019

2120
**webpack.config.js**
2221

2322
```javascript
2423
module.exports = {
2524
output: {
2625
filename: 'bundle.js',
27-
path: '/home/proj/public/assets'
2826
}
2927
};
3028
```
3129

32-
This configuration would output a single `bundle.js` file into the `/home/proj/public/assets` directory.
30+
This configuration would output a single `bundle.js` file into the `dist` directory.
3331

3432

3533
## Multiple Entry Points

src/content/concepts/plugins.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ contributors:
66
- jhnns
77
- rouzbeh84
88
- johnstew
9+
- MisterDev
910
- byzyk
1011
---
1112

@@ -32,7 +33,7 @@ class ConsoleLogOnBuildWebpackPlugin {
3233
}
3334
```
3435

35-
First parameter of the tap method of the compiler hook should be a camelized version of the plugin name. It is advisable to use a constant for this so it can be reused in all hooks.
36+
The first parameter of the tap method of the compiler hook should be a camelized version of the plugin name. It is advisable to use a constant for this so it can be reused in all hooks.
3637

3738
## Usage
3839

@@ -65,6 +66,7 @@ module.exports = {
6566
]
6667
},
6768
plugins: [
69+
new webpack.ProgressPlugin(),
6870
new HtmlWebpackPlugin({template: './src/index.html'})
6971
]
7072
};
@@ -73,7 +75,7 @@ module.exports = {
7375

7476
### Node API
7577

76-
?> Even when using the Node API, users should pass plugins via the `plugins` property in the configuration. Using `compiler.apply` should not be the recommended way.
78+
When using the Node API, you can also pass plugins via the `plugins` property in the configuration.
7779

7880
__some-node-script.js__
7981

@@ -82,7 +84,8 @@ const webpack = require('webpack'); //to access webpack runtime
8284
const configuration = require('./webpack.config.js');
8385

8486
let compiler = webpack(configuration);
85-
compiler.apply(new webpack.ProgressPlugin());
87+
88+
new webpack.ProgressPlugin().apply(compiler);
8689

8790
compiler.run(function(err, stats) {
8891
// ...

src/content/configuration/configuration-types.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ contributors:
66
- skipjack
77
- kbariotis
88
- simon04
9+
- fadysamirsadek
910
- byzyk
1011
---
1112

@@ -65,14 +66,18 @@ module.exports = [{
6566
filename: './dist-amd.js',
6667
libraryTarget: 'amd'
6768
},
69+
name: 'amd',
6870
entry: './app.js',
6971
mode: 'production',
7072
}, {
7173
output: {
7274
filename: './dist-commonjs.js',
7375
libraryTarget: 'commonjs'
7476
},
77+
name: 'commonjs',
7578
entry: './app.js',
7679
mode: 'production',
7780
}];
7881
```
82+
83+
T> If you pass a name to `--config-name` flag, webpack will only build that specific configuration.

src/content/configuration/optimization.md

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ T> Learn how [mode](/concepts/mode/) works.
3939

4040
## `optimization.minimizer`
4141

42-
`UglifyjsWebpackPlugin | [UglifyjsWebpackPlugin]`
42+
`[UglifyjsWebpackPlugin]`
4343

4444
Allows you to override the default minimizer by providing a different one or more customized [UglifyjsWebpackPlugin](/plugins/uglifyjs-webpack-plugin/) instances.
4545

@@ -69,11 +69,35 @@ By default webpack v4+ provides new common chunks strategies out of the box for
6969

7070
`object` `string` `boolean`
7171

72-
Setting `optimization.runtimeChunk` to `true` adds an additional chunk to each entry point containing only the runtime.
73-
It is possible to use preset mode of the plugin by providing a string value:
72+
Setting `optimization.runtimeChunk` to `true` or `"multiple"` adds an additional chunk to each entrypoint containing only the runtime. This setting is an alias for:
7473

75-
- `single`: creates a runtime file to be shared for all generated chunks.
76-
- `multiple`: creates multiple runtime files for common chunks.
74+
__webpack.config.js__
75+
76+
```js
77+
module.exports = {
78+
//...
79+
optimization: {
80+
runtimeChunk: {
81+
name: entrypoint => `runtime~${entrypoint.name}`
82+
}
83+
}
84+
};
85+
```
86+
87+
The value `"single"` instead creates a runtime file to be shared for all generated chunks. This setting is an alias for:
88+
89+
__webpack.config.js__
90+
91+
```js
92+
module.exports = {
93+
//...
94+
optimization: {
95+
runtimeChunk: {
96+
name: 'runtime'
97+
}
98+
}
99+
};
100+
```
77101

78102
By setting `optimization.runtimeChunk` to `object` it is only possible to provide the `name` property which stands for the name or name factory for the runtime chunks.
79103

@@ -135,7 +159,7 @@ module.exports = {
135159

136160
`boolean: false`
137161

138-
Tells webpack to use readable chunk identifiers for better debugging. This option is enabled by default for [mode](/concepts/mode/) `development` and disabled for [mode](/concepts/mode/) `production` if no option is provided in webpack config.
162+
Tells webpack to use readable chunk identifiers for better debugging. This option is enabled by default for [mode](/concepts/mode/) `development` and disabled for [mode](/concepts/mode/) `production` if no option is provided in webpack config.
139163

140164
__webpack.config.js__
141165

@@ -324,4 +348,37 @@ module.exports = {
324348
concatenateModules: true
325349
}
326350
};
327-
```
351+
```
352+
353+
## `optimization.sideEffects`
354+
355+
`bool`
356+
357+
Tells webpack to recognise the [`sideEffects`](https://github.com/webpack/webpack/blob/master/examples/side-effects/README.md) flag in `package.json` or rules to skip over modules which are flagged to contain no side effects when exports are not used.
358+
359+
__package.json__
360+
361+
``` json
362+
{
363+
"name": "awesome npm module",
364+
"version": "1.0.0",
365+
"sideEffects": false
366+
}
367+
```
368+
369+
T> Please note that `sideEffects` should be in the npm module's `package.json` file and doesn't mean that you need to set `sideEffects` to `false` in your own project's `package.json` which requires that big module.
370+
371+
`optimization.sideEffects` depends on [`optimization.providedExports`](#optimization-providedexports) to be enabled. This dependency has a build time cost, but eliminating modules has positive impact on performance because of less code generation. Effect of this optimization depends on your codebase, try it for possible performance wins.
372+
373+
By default `optimization.sideEffects` is enabled in `production` [mode](/concepts/mode/) and disabled elsewise.
374+
375+
__webpack.config.js__
376+
377+
```js
378+
module.exports = {
379+
//...
380+
optimization: {
381+
sideEffects: true
382+
}
383+
};
384+
```

0 commit comments

Comments
 (0)