mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 17:25:39 +01:00
Merge pull request #19 from brijeshb42/master
Add support for webpack 3
This commit is contained in:
commit
98d97d8541
1 changed files with 29 additions and 17 deletions
|
|
@ -1,4 +1,27 @@
|
||||||
const webpack = require('webpack');
|
const webpack = require('webpack');
|
||||||
|
const webpackVersion = require('webpack/package.json').version;
|
||||||
|
const SingleEntryPlugin = require('webpack/lib/SingleEntryPlugin');
|
||||||
|
const LoaderTargetPlugin = require('webpack/lib/LoaderTargetPlugin');
|
||||||
|
const WebWorkerTemplatePlugin = require('webpack/lib/webworker/WebWorkerTemplatePlugin');
|
||||||
|
|
||||||
|
function getCompilerHook(compiler, {id, entry, filename, chunkFilename, plugins}) {
|
||||||
|
return function(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 WebWorkerTemplatePlugin(),
|
||||||
|
new LoaderTargetPlugin('webworker'),
|
||||||
|
new SingleEntryPlugin(compiler.context, entry, 'main'),
|
||||||
|
]);
|
||||||
|
plugins.forEach((plugin) => plugin.apply(childCompiler));
|
||||||
|
childCompiler.runAsChild(callback);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class AddWorkerEntryPointPlugin {
|
class AddWorkerEntryPointPlugin {
|
||||||
constructor({
|
constructor({
|
||||||
|
|
@ -12,23 +35,12 @@ class AddWorkerEntryPointPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
apply(compiler) {
|
apply(compiler) {
|
||||||
const { id, entry, filename, chunkFilename, plugins } = this.options;
|
const compilerHook = getCompilerHook(compiler, this.options);
|
||||||
compiler.hooks.make.tapAsync('AddWorkerEntryPointPlugin', (compilation, callback) => {
|
if (webpackVersion < '4') {
|
||||||
const outputOptions = {
|
compiler.plugin('make', compilerHook);
|
||||||
filename,
|
} else {
|
||||||
chunkFilename,
|
compiler.hooks.make.tapAsync('AddWorkerEntryPointPlugin', compilerHook);
|
||||||
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);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue