You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
monaco-editor/plugins/AddWorkerEntryPointPlugin.js

36 lines
1.1 KiB
JavaScript

const webpack = require('webpack');
class AddWorkerEntryPointPlugin {
constructor({
id,
entry,
filename,
chunkFilename = undefined,
plugins = undefined,
}) {
this.options = { id, entry, filename, chunkFilename, plugins };
}
apply(compiler) {
const { id, entry, filename, chunkFilename, plugins } = this.options;
compiler.hooks.make.tapAsync('AddWorkerEntryPointPlugin', (compilation, callback) => {
const outputOptions = {
filename,
chunkFilename,
publicPath: compilation.outputOptions.publicPath,
// HACK: globalObject is necessary to fix https://github.com/webpack/webpack/issues/6642
globalObject: 'this',
};
const childCompiler = compilation.createChildCompiler(id, outputOptions, [
new webpack.webworker.WebWorkerTemplatePlugin(),
new webpack.LoaderTargetPlugin('webworker'),
new webpack.SingleEntryPlugin(compiler.context, entry, 'main'),
]);
plugins.forEach((plugin) => plugin.apply(childCompiler));
childCompiler.runAsChild(callback);
});
}
}
module.exports = AddWorkerEntryPointPlugin;