-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebpack.config.js
More file actions
54 lines (50 loc) · 1.35 KB
/
Copy pathwebpack.config.js
File metadata and controls
54 lines (50 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const HtmlWebpackPlugin = require('html-webpack-plugin');
/**
* The class to try out a few things with the webpack plugins. I've read that
* creating webpack plugins require users to read the webpack code to understand
* the compilation process.
*/
class LearnPlugin {
pluginName = 'LearnPlugin';
apply(compiler) {
compiler.hooks.done.tap(this.pluginName, (stats) => {
// console.log('LearnPlugin: done');
});
compiler.hooks.emit.tap(this.pluginName, (compilation) => {
// console.log({ assets: Object.keys(compilation.assets) });
// console.log({ module });
});
compiler.hooks.emit.tapAsync(this.pluginName, (compilation, callback) => {
Object.keys(compilation.assets).forEach((assetName) => {
if (assetName.endsWith('.js')) {
const assetContent = compilation.assets[assetName].source();
// console.log({ assetName, assetContent });
}
});
callback();
});
}
}
/** @type {import('webpack').Configuration} */
const config = {
entry: './entry.js',
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: './index.html',
inject: 'body',
}),
new LearnPlugin(),
],
};
module.exports = config;