forked from yarnpkg/berry
/
webpack.config.hook.js
40 lines (35 loc) Β· 1.1 KB
/
webpack.config.hook.js
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
const {makeConfig} = require(`@yarnpkg/builder/sources/tools/makeConfig`);
const {RawSource} = require(`webpack-sources`);
const {brotliCompressSync} = require(`zlib`);
module.exports = makeConfig({
context: __dirname,
mode: `production`,
optimization: {
minimize: false,
},
entry: {
[`hook`]: `./sources/loader/_entryPoint.ts`,
},
output: {
filename: `[name].js`,
path: `${__dirname}/sources`,
libraryExport: `default`,
libraryTarget: `umd`,
library: `pnpHook`,
},
plugins: [
{apply: compiler => {
compiler.hooks.compilation.tap(`MyPlugin`, compilation => {
compilation.hooks.optimizeChunkAssets.tap(`MyPlugin`, chunks => {
for (const chunk of chunks) {
for (const file of chunk.files) {
compilation.assets[file] = new RawSource(
`module.exports = require('zlib').brotliDecompressSync(Buffer.from('${brotliCompressSync(compilation.assets[file].source().replace(/\r\n/g, `\n`)).toString(`base64`)}', 'base64')).toString();\n`
);
}
}
});
});
}},
],
});