Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import validateOptions from 'schema-utils';
import NodeTargetPlugin from 'webpack/lib/node/NodeTargetPlugin';
import SingleEntryPlugin from 'webpack/lib/SingleEntryPlugin';
import WebWorkerTemplatePlugin from 'webpack/lib/webworker/WebWorkerTemplatePlugin';
import ExternalsPlugin from 'webpack/lib/ExternalsPlugin';

import getWorker from './workers/';
import LoaderError from './Error';
Expand Down Expand Up @@ -43,6 +44,8 @@ export function pitch(request) {

const worker = {};

const compilerOptions = this._compiler.options || {};

worker.options = {
filename,
chunkFilename: `[id].${filename}`,
Expand All @@ -54,6 +57,15 @@ export function pitch(request) {

// Tapable.apply is deprecated in [email protected].
// The plugins should now call apply themselves.
if (compilerOptions.externals) {
const externalsType =
compilerOptions.output.libraryTarget ||
compilerOptions.externalsType ||
(compilerOptions.output.library && compilerOptions.output.library.type) ||
(compilerOptions.output.module ? 'module' : 'var');
new ExternalsPlugin(externalsType, compilerOptions.externals).apply(worker.compiler);
}

new WebWorkerTemplatePlugin(worker.options).apply(worker.compiler);

if (this.target !== 'webworker' && this.target !== 'web') {
Expand Down