mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 17:25:39 +01:00
Add webpack loader plugin
This commit is contained in:
parent
7ff49af7a6
commit
7c18d303e6
5 changed files with 623 additions and 0 deletions
35
plugins/AddWorkerEntryPointPlugin.js
Normal file
35
plugins/AddWorkerEntryPointPlugin.js
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
class AddWorkerEntryPointPlugin {
|
||||
constructor(webpack, {
|
||||
id,
|
||||
entry,
|
||||
filename,
|
||||
chunkFilename = undefined,
|
||||
plugins = undefined,
|
||||
}) {
|
||||
this.webpack = webpack;
|
||||
this.options = { id, entry, filename, chunkFilename, plugins };
|
||||
}
|
||||
|
||||
apply(compiler) {
|
||||
const webpack = this.webpack;
|
||||
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;
|
||||
Loading…
Add table
Add a link
Reference in a new issue