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
+ btn.innerHTML = 'Click me and check the console!';
60
+
+ btn.onclick = printMe;
61
61
+
62
-
+element.appendChild(btn);
63
-
64
-
return element;
65
-
}
66
-
67
-
document.body.appendChild(component());
62
+
+ element.appendChild(btn);
63
+
+
64
+
return element;
65
+
}
66
+
67
+
document.body.appendChild(component());
68
68
```
69
69
70
70
Let's also update our `dist/index.html` file, in preparation for webpack to split out entries:
71
71
72
72
__dist/index.html__
73
73
74
74
```diff
75
-
<!doctype html>
76
-
<html>
77
-
<head>
78
-
- <title>Asset Management</title>
79
-
+ <title>Output Management</title>
80
-
+ <script src="./print.bundle.js"></script>
81
-
</head>
82
-
<body>
83
-
- <script src="./bundle.js"></script>
84
-
+ <script src="./app.bundle.js"></script>
85
-
</body>
86
-
</html>
75
+
<!DOCTYPE html>
76
+
<html>
77
+
<head>
78
+
<meta charset="utf-8" />
79
+
- <title>Asset Management</title>
80
+
+ <title>Output Management</title>
81
+
+ <script src="./print.bundle.js"></script>
82
+
</head>
83
+
<body>
84
+
- <script src="bundle.js"></script>
85
+
+ <script src="./app.bundle.js"></script>
86
+
</body>
87
+
</html>
87
88
```
88
89
89
90
Now adjust the config. We'll be adding our `src/print.js` as a new entry point (`print`) and we'll change the output as well, so that it will dynamically generate bundle names, based on the entry point names:
90
91
91
92
__webpack.config.js__
92
93
93
94
```diff
94
-
const path = require('path');
95
-
96
-
module.exports = {
97
-
-entry: './src/index.js',
98
-
+entry: {
99
-
+app: './src/index.js',
100
-
+print: './src/print.js',
101
-
+},
102
-
output: {
103
-
-filename: 'bundle.js',
104
-
+filename: '[name].bundle.js',
105
-
path: path.resolve(__dirname, 'dist'),
106
-
},
107
-
};
95
+
const path = require('path');
96
+
97
+
module.exports = {
98
+
- entry: './src/index.js',
99
+
+ entry: {
100
+
+ app: './src/index.js',
101
+
+ print: './src/print.js',
102
+
+ },
103
+
output: {
104
+
- filename: 'bundle.js',
105
+
+ filename: '[name].bundle.js',
106
+
path: path.resolve(__dirname, 'dist'),
107
+
},
108
+
};
108
109
```
109
110
110
111
Let's run `npm run build` and see what this generates:
We can see that webpack generates our `print.bundle.js` and `app.bundle.js` files, which we also specified in our `index.html` file. if you open `index.html` in your browser, you can see what happens when you click the button.
Before we do a build, you should know that the `HtmlWebpackPlugin` by default will generate its own `index.html` file, even though we already have one in the `dist/` folder. This means that it will replace our `index.html` file with a newly generated one. Let's see what happens when we do an `npm run build`:
157
163
158
164
```bash
159
165
...
160
-
Asset Size Chunks Chunk Names
161
-
print.bundle.js 544 kB 0 [emitted] [big] print
162
-
app.bundle.js 2.81 kB 1 [emitted] app
163
-
index.html 249 bytes [emitted]
164
-
...
166
+
[webpack-cli] Compilation finished
167
+
asset app.bundle.js 69.5 KiB [compared for emit] [minimized] (name: app) 1 related asset
168
+
asset print.bundle.js 316 bytes [compared for emit] [minimized] (name: print)
If you open `index.html` in your code editor, you'll see that the `HtmlWebpackPlugin` has created an entirely new file for you and that all the bundles are automatically added.
Now run an `npm run build` and inspect the `/dist` folder. If everything went well you should now only see the files generated from the build and no more old files!
@@ -212,7 +223,7 @@ Now run an `npm run build` and inspect the `/dist` folder. If everything went we
212
223
213
224
You might be wondering how webpack and its plugins seem to "know" what files are being generated. The answer is in the manifest that webpack keeps to track how all the modules map to the output bundles. If you're interested in managing webpack's [`output`](/configuration/output) in other ways, the manifest would be a good place to start.
214
225
215
-
The manifest data can be extracted into a json file for easy consumption using the [`WebpackManifestPlugin`](https://github.com/danethurber/webpack-manifest-plugin).
226
+
The manifest data can be extracted into a json file for easy consumption using the [`WebpackManifestPlugin`](https://github.com/shellscape/webpack-manifest-plugin).
216
227
217
228
We won't go through a full example of how to use this plugin within your projects, but you can read up on [the concept page](/concepts/manifest) and the [caching guide](/guides/caching) to find out how this ties into long term caching.
0 commit comments