mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 18:32:56 +01:00
Prevent bundling worker fallbacks into compiled workers
This commit is contained in:
parent
a47ca0bf3e
commit
2535fd5a79
2 changed files with 36 additions and 13 deletions
|
|
@ -1,15 +1,22 @@
|
|||
class AddWorkerEntryPointPlugin {
|
||||
constructor(webpack, { id, entry, output }) {
|
||||
constructor(webpack, {
|
||||
id,
|
||||
entry,
|
||||
filename,
|
||||
chunkFilename = undefined,
|
||||
plugins = undefined,
|
||||
}) {
|
||||
this.webpack = webpack;
|
||||
this.options = { id, entry, output };
|
||||
this.options = { id, entry, filename, chunkFilename, plugins };
|
||||
}
|
||||
|
||||
apply(compiler) {
|
||||
const webpack = this.webpack;
|
||||
const { id, entry, output } = this.options;
|
||||
compiler.plugin('make', (compilation, callback) => {
|
||||
const { id, entry, filename, chunkFilename, plugins } = this.options;
|
||||
compiler.hooks.make.tapAsync('AddWorkerEntryPointPlugin', (compilation, callback) => {
|
||||
const outputOptions = {
|
||||
filename: output,
|
||||
filename,
|
||||
chunkFilename,
|
||||
publicPath: compilation.outputOptions.publicPath,
|
||||
// HACK: globalObject is necessary to fix https://github.com/webpack/webpack/issues/6642
|
||||
globalObject: 'this',
|
||||
|
|
@ -17,8 +24,9 @@ class AddWorkerEntryPointPlugin {
|
|||
const childCompiler = compilation.createChildCompiler(id, outputOptions, [
|
||||
new webpack.webworker.WebWorkerTemplatePlugin(),
|
||||
new webpack.LoaderTargetPlugin('webworker'),
|
||||
new webpack.SingleEntryPlugin(this.context, entry, 'main'),
|
||||
new webpack.SingleEntryPlugin(compiler.context, entry, 'main'),
|
||||
]);
|
||||
plugins.forEach((plugin) => plugin.apply(childCompiler));
|
||||
childCompiler.runAsChild(callback);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue