-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (32 loc) · 1.05 KB
/
index.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
const ConcatSource = require('webpack-sources').ConcatSource
class BitwigWebpackPlugin {
apply(compiler) {
compiler.hooks.thisCompilation.tap('BitwigWebpackPlugin', (compilation) => {
compilation.hooks.processAssets.tap(
{
name: 'BitwigWebpackPlugin',
stage:
compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_INLINE,
},
() => {
const entryNames = [...compilation.entrypoints.keys()]
entryNames.forEach((entryName) => {
const entryFile = `${entryName}.js`
const files = compilation.entrypoints
.get(entryName)
.getFiles()
.filter((f) => f !== entryFile)
const header = `window = globalThis;\n${files
.map((file) => `load('${file}');`)
.join('\n')}\n`
compilation.assets[entryFile] = new ConcatSource(
header,
compilation.assets[entryFile]
)
})
}
)
})
}
}
module.exports = BitwigWebpackPlugin