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/entry-points.md
+4-20Lines changed: 4 additions & 20 deletions
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,7 @@ contributors:
5
5
- TheLarkInn
6
6
- chrisVillanueva
7
7
- byzyk
8
+
- sokra
8
9
---
9
10
10
11
As mentioned in [Getting Started](/guides/getting-started/#using-a-configuration), 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.
@@ -61,26 +62,9 @@ T> **"Scalable webpack configurations"** are ones that can be reused and combine
61
62
62
63
Below is a list of entry configurations and their real-world use cases:
63
64
64
-
65
65
### Separate App and Vendor Entries
66
66
67
-
**webpack.config.js**
68
-
69
-
```javascript
70
-
module.exports= {
71
-
entry: {
72
-
app:'./src/app.js',
73
-
vendors:'./src/vendors.js'
74
-
}
75
-
};
76
-
```
77
-
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).
79
-
80
-
**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).
81
-
82
-
?> Consider removing this scenario in favor of the DllPlugin, which provides a better vendor-splitting.
83
-
67
+
T> In webpack version < 4 it was common to add vendors as separate entrypoint to compile it as separate file (in combination with the `CommonsChunkPlugin`). This is discouraged in webpack 4. Instead the `optimization.splitChunks` option takes care of separating vendors and app modules and creating a separate file. **Do not** create a entry for vendors or other stuff which is not the starting point of execution.
84
68
85
69
### Multi Page Application
86
70
@@ -100,6 +84,6 @@ module.exports = {
100
84
101
85
**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:
102
86
103
-
- 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.
87
+
- Use `optimization.splitChunks` 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.
104
88
105
89
T> As a rule of thumb: for each HTML document use exactly one entry point.
Plugins grant unlimited opportunity to perform customizations within the webpack build system. This allows you to create custom asset types, perform unique build modifications, or even enhance the webpack runtime while using middleware. The following are some features of webpack that become useful while writing plugins.
@@ -10,63 +12,66 @@ Plugins grant unlimited opportunity to perform customizations within the webpack
10
12
After a compilation is sealed, all structures within the compilation may be traversed.
// Explore each module within the chunk (built inputs):
21
+
chunk.modules.forEach(module=> {
22
+
// Explore each source file path that was included into the module:
23
+
module.fileDependencies.forEach(filepath=> {
24
+
// we've learned a lot about the source structure now...
25
+
});
25
26
});
26
-
});
27
27
28
-
// Explore each asset filename generated by the chunk:
29
-
chunk.files.forEach(function(filename) {
30
-
// Get the asset source for each file generated by the chunk:
31
-
var source =compilation.assets[filename].source();
28
+
// Explore each asset filename generated by the chunk:
29
+
chunk.files.forEach(filename=> {
30
+
// Get the asset source for each file generated by the chunk:
31
+
var source =compilation.assets[filename].source();
32
+
});
32
33
});
33
-
});
34
-
35
-
callback();
36
-
});
37
-
};
38
34
35
+
callback();
36
+
});
37
+
}
38
+
}
39
39
module.exports= MyPlugin;
40
40
```
41
41
42
-
-`compilation.modules`: An array of modules (built inputs) in the compilation. Each module manages the build of a raw file from your source library.
43
-
-`module.fileDependencies`: An array of source file paths included into a module. This includes the source JavaScript file itself (ex: `index.js`), and all dependency asset files (stylesheets, images, etc) that it has required. Reviewing dependencies is useful for seeing what source files belong to a module.
44
-
-`compilation.chunks`: An array of chunks (build outputs) in the compilation. Each chunk manages the composition of a final rendered assets.
45
-
-`chunk.modules`: An array of modules that are included into a chunk. By extension, you may look through each module's dependencies to see what raw source files fed into a chunk.
46
-
-`chunk.files`: An array of output filenames generated by the chunk. You may access these asset sources from the `compilation.assets` table.
42
+
*`compilation.modules`: An array of modules (built inputs) in the compilation. Each module manages the build of a raw file from your source library.
43
+
*`module.fileDependencies`: An array of source file paths included into a module. This includes the source JavaScript file itself (ex: `index.js`), and all dependency asset files (stylesheets, images, etc) that it has required. Reviewing dependencies is useful for seeing what source files belong to a module.
44
+
*`compilation.chunks`: An array of chunks (build outputs) in the compilation. Each chunk manages the composition of a final rendered assets.
45
+
*`chunk.modules`: An array of modules that are included into a chunk. By extension, you may look through each module's dependencies to see what raw source files fed into a chunk.
46
+
*`chunk.files`: An array of output filenames generated by the chunk. You may access these asset sources from the `compilation.assets` table.
47
47
48
48
### Monitoring the watch graph
49
49
50
50
While running webpack middleware, each compilation includes a `fileDependencies` array (what files are being watched) and a `fileTimestamps` hash that maps watched file paths to a timestamp. These are extremely useful for detecting what files have changed within the compilation:
0 commit comments