Skip to content

Instantly share code, notes, and snippets.

@boushley
Created May 15, 2017 20:19
Show Gist options
  • Save boushley/a18618f35f6fa50ca970ca2e83096674 to your computer and use it in GitHub Desktop.
Save boushley/a18618f35f6fa50ca970ca2e83096674 to your computer and use it in GitHub Desktop.
Boostrap Webpack DLL Chunk
// This plugin modifies the generated webpack code to execute a module within the DLL bundle in addition to preserving
// the default behavior of exporting the webpack require function
class DllBootstrapPlugin {
constructor(options) {
this.options = options || {}
}
apply(compiler) {
compiler.plugin('compilation', (compilation) => {
compilation.mainTemplate.plugin('startup', (source, chunk) => {
const bootstrapEntry = this.options[chunk.name]
if (bootstrapEntry) {
const module = chunk.modules.find((m) => m.rawRequest === bootstrapEntry)
source = `// Include bootstrap entry
__webpack_require__(${module.id});
${source}`
}
return source
})
})
}
}
module.exports = DllBootstrapPlugin
var webpack = require('webpack')
var BootstrapPlugin = require('./dllBootstrapPlugin.js')
var bootstrapModule = path.resolve(__dirname, 'config', 'ravenBootstrap')
var config = {
entry: {
vendor: [
'hls.js',
...
],
needBootstrap: ['someModule', bootstrapModule],
},
output: {
path: buildDir,
filename: '[name].js',
library: '[name]_lib',
},
plugins: [
new webpack.DllPlugin({
context: __dirname,
name: '[name]_lib',
path: path.resolve(buildDir, '[name]-manifest.json'),
}),
new BootstrapPlugin({ needBootstrap: bootstrapModule }),
],
}
module.exports = config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment