Skip to content

Commit 9ca2235

Browse files
committed
added fixed and todo from review
1 parent 8fe14fd commit 9ca2235

File tree

6 files changed

+52
-28
lines changed

6 files changed

+52
-28
lines changed

content/concepts/configuration.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
11
---
22
title: Configuration
3+
contributors:
34
---
45

5-
You may have noticed that few webpack configurations look exactly alike. This is because **webpack's configuration file is a JavaScript file that exports an object.** This object, is then parsed by webpack based upon its defined properties.
6+
You may have noticed that few webpack configurations look exactly alike. This is because **webpack's configuration file is a JavaScript file that exports an object.** This object is then processed by webpack based upon its defined properties.
7+
8+
Because it's a standard node.js CommonJs module, you **can do the following**:
9+
10+
* import other files via `require(...)`
11+
* use utilities on npm via `require(...)`
12+
* use JS controlflow expressions i. e. the `?:` operator
13+
* use constants or variables for often used values
14+
* write and execute function to generate a part of the configuration
15+
16+
Use these features when appropriate.
17+
18+
**You should NOT use the following things**. Technically you could use them, but it's **not recommended**:
19+
20+
* Access CLI arguments, when using the webpack CLI (instead write your own CLI, or use `--env`)
21+
* Export non-deterministic values (calling webpack twice should result in the same output files)
22+
* Write very long configurations (instead split the configuration into multiple files)
623

724
The following examples below describe how webpack's configuration object can be both expressive and configurable because _it is code_:
825

@@ -35,8 +52,8 @@ var baseConfig = {
3552
entry: './entry.js'
3653
},
3754
output: {
38-
filename: '[name].js',
39-
path: path.resolve(__dirname, 'dist')
55+
path: path.resolve(__dirname, 'dist'),
56+
filename: '[name].js'
4057
},
4158
plugins: [
4259
new webpack.optimize.CommonsChunkPlugin({

content/concepts/entry-points.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
---
22
title: Entry Points
33
sort: 0
4+
contributors:
5+
- TheLarkInn
46
---
57

68
Like we mentioned in the [introduction](./), there are multiple ways to define the `entry` property in your webpack configuration. We will show you the ways you **can** configure the `entry` property, in addition to explaining why it may be useful to you.
@@ -73,6 +75,8 @@ const config = {
7375

7476
**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](/how-to/cache).
7577

78+
?> Consider removing this scenario in favor of the DllPlugin, which provides a better vendor-splitting.
79+
7680
#### Multi Page Application
7781

7882
**webpack.config.js**
@@ -82,16 +86,15 @@ const config = {
8286
entry: {
8387
pageOne: './src/pageOne/index.js',
8488
pageTwo: './src/pageTwo/index.js',
85-
pageThree: './src/pageThree/index.js',
86-
vendors: './src/vendors.js'
89+
pageThree: './src/pageThree/index.js'
8790
}
8891
};
8992
```
9093

91-
**What does this do?** We are telling webpack that we would like 4 separate dependency graphs (like the above example).
94+
**What does this do?** We are telling webpack that we would like 3 separate dependency graphs (like the above example).
9295

9396
**Why?** In a multi-page application, the server is going to fetch a new HTML document for you. The page reloads this new document and assets are redownloaded. However, this gives us the unique opportunity to do multiple things:
9497

9598
- Use `CommonsChunkPlugin` to create bundles of shared application code between each page. Multi-page applications that reuse a lot of code/modules between entry points can greatly benefit from these techniques, as the amount of entry points increase.
9699

97-
- Set up [long-term vendor-caching](/how-to/cache) with the same plugin and techniques seen in the first example.
100+
T> As a rule of thumb: for one HTML use exactly one entry point.

content/concepts/index.md

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,14 @@ The simplest example is seen below:
2020
**webpack.config.js**
2121

2222
```javascript
23-
const config = {
23+
module.exports = {
2424
entry: './path/to/my/entry/file.js'
2525
};
26-
27-
module.exports = config;
2826
```
2927

3028
There are multiple ways to declare your `entry` property that are specific to your application's needs.
3129

32-
[**Learn more!**](/concepts/entry-points)
30+
[Learn more!](/concepts/entry-points)
3331

3432
## Output
3533

@@ -38,11 +36,11 @@ Once you've bundled all of your assets together, we still need to tell webpack *
3836
**webpack.config.js**
3937

4038
```javascript
41-
const config = {
39+
module.exports = {
4240
entry: './path/to/my/entry/file.js',
4341
output: {
44-
filename: 'my-first-webpack.bundle.js',
45-
path: './dist'
42+
path: path.resolve(__dirname, 'dist'),
43+
filename: 'my-first-webpack.bundle.js'
4644
}
4745
};
4846
```
@@ -53,7 +51,7 @@ T> You may see the term **emitted** or **emit** used throughout our documentatio
5351

5452
The `output` property has [many more configurable features](/configuration), but let's spend some time understanding some of the most common use cases for the `output` property.
5553

56-
[**Learn more!**](/concepts/output)
54+
[Learn more!](/concepts/output)
5755

5856

5957
## Loaders
@@ -65,34 +63,34 @@ The goal is to have all of the assets in your project to be **webpack's** concer
6563
At a high level, they have two purposes in your webpack config.
6664

6765
1. Identify what files should be transformed by a certain loader. (`test` property)
68-
2. Transform that file so that it can be added to your dependency graph (and eventually your bundle). (`loader` property)
66+
2. Transform that file so that it can be added to your dependency graph (and eventually your bundle). (`use` property)
6967

7068
**webpack.config.js**
7169

7270
```javascript
7371
const config = {
7472
entry: './path/to/my/entry/file.js',
7573
output: {
76-
filename: 'my-first-webpack.bundle.js',
77-
path: './dist'
74+
path: path.resolve(__dirname, 'dist'),
75+
filename: 'my-first-webpack.bundle.js'
7876
},
7977
module: {
80-
loaders: [
81-
{test: /\.(js|jsx)$/, loader: 'babel-loader'}
78+
rules: [
79+
{test: /\.(js|jsx)$/, use: 'babel-loader'}
8280
]
8381
}
8482
};
8583
```
8684

87-
In the configuration above we have defined our loader with it's two required properties: `test`, and `loader`. This tells webpack's compiler the following:
85+
In the configuration above we have defined a rules which used our loader with it's two required properties: `test`, and `use`. This tells webpack's compiler the following:
8886

89-
> "Hey webpack compiler, when you come across a path that resolves to a '.js' or '.jsx' file inside of a `require()`/`import` statement, use the `babel-loader` to transform it before you add it to the bundle".
87+
> "Hey webpack compiler, when you come across a path that resolves to a '.js' or '.jsx' file inside of a `require()`/`import` statement, **use** the `babel-loader` to transform it before you add it to the bundle".
9088

91-
W> It is important to remember when defining loaders in your webpack config, you are defining them under `module.loaders`, and not `loaders`.
89+
W> It is important to remember when defining rules in your webpack config, you are defining them under `module.rules`, and not `rules`. But webpack will yell at you when doing this incorrectly.
9290

9391
There are more specific properties to define on loaders that we haven't yet covered.
9492

95-
[**Learn more!**](/concepts/loaders)
93+
[Learn more!](/concepts/loaders)
9694

9795
## Plugins
9896

@@ -130,4 +128,4 @@ There are many plugins that webpack provides out of the box! Check out our [list
130128

131129
Using plugins in your webpack config is straight-forward, however there are many use-cases that are worth discussing further.
132130

133-
[**Learn more!**](/concepts/plugins)
131+
[Learn more!](/concepts/plugins)

content/concepts/loaders.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
title: Loaders
33
sort: 2
4+
contributors:
45
---
5-
> module.loaders configuration option
6-
> test, include, exclude, loader, query
6+
7+
?> Write about how rules work and what's the purpose of loaders.

content/concepts/output.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
title: Output
33
sort: 1
4+
contributors:
45
---
56

67
Options affecting the output of the compilation. `output` options tell Webpack how to write the compiled files to disk. Note, that while there can be multiple `entry` points, only one `output` configuration is specified.

content/concepts/plugins.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ contributors:
66
- jhnns
77
---
88

9-
**Plugins** are the [backbone](https://github.com/webpack/tapable) of webpack. webpack itself is built on the **same plugin system** that you use in your webpack configuration!!
9+
**Plugins** are the [backbone](https://github.com/webpack/tapable) of webpack. webpack itself is built on the **same plugin system** that you use in your webpack configuration!
1010

1111
They also serve the purpose of doing **anything else** that a [loader](/concepts/loaders) cannot do.
1212

@@ -31,6 +31,8 @@ ConsoleLogOnBuildWebpackPlugin.prototype.apply = function(compiler) {
3131
};
3232
```
3333

34+
T> As clever JS developer you may remember the `Function.prototype.apply` method. Because of this method you can pass any function as plugin (`this` will point to the `compiler`). You can use this style to inline custom plugins in your configuration.
35+
3436
## Usage
3537

3638
Since **plugins** can take arguments/options, you must pass a `new` instance to the `plugins` property in your webpack configuration.
@@ -70,6 +72,8 @@ module.exports = config;
7072

7173
### Node API
7274

75+
?> 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.
76+
7377
**some-node-script.js**
7478

7579
```javascript

0 commit comments

Comments
 (0)