worker-plugin
Advanced tools
Comparing version 3.0.0 to 3.1.0
@@ -6,2 +6,3 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
var WebWorkerTemplatePlugin = _interopDefault(require('webpack/lib/webworker/WebWorkerTemplatePlugin')); | ||
var FetchCompileWasmTemplatePlugin = _interopDefault(require('webpack/lib/web/FetchCompileWasmTemplatePlugin')); | ||
var WORKER_PLUGIN_SYMBOL = _interopDefault(require('./symbol.js')); | ||
@@ -30,6 +31,7 @@ | ||
var compilerOptions = this._compiler.options || {}; | ||
var pluginOptions = compilerOptions.plugins.find(function (p) { return p[WORKER_PLUGIN_SYMBOL]; }).options; | ||
if (!hasWarned && compilerOptions.output && compilerOptions.output.globalObject === 'window') { | ||
if (pluginOptions.globalObject == null && !hasWarned && compilerOptions.output && compilerOptions.output.globalObject === 'window') { | ||
hasWarned = true; | ||
console.warn('Warning (workerize-loader): output.globalObject is set to "window". It should be set to "self" or "this" to support HMR in Workers.'); | ||
console.warn('Warning (worker-plugin): output.globalObject is set to "window". It must be set to "self" to support HMR in Workers.'); | ||
} | ||
@@ -42,5 +44,4 @@ | ||
chunkFilename: chunkFilename, | ||
globalObject: 'self' | ||
globalObject: pluginOptions.globalObject || 'self' | ||
}; | ||
var pluginOptions = compilerOptions.plugins.find(function (p) { return p[WORKER_PLUGIN_SYMBOL]; }).options; | ||
var plugins = (pluginOptions.plugins || []).map(function (plugin) { | ||
@@ -54,3 +55,3 @@ if (typeof plugin !== 'string') { | ||
if (!found) { | ||
console.warn(("Warning (workerize-loader): Plugin \"" + plugin + "\" is not found.")); | ||
console.warn(("Warning (worker-plugin): Plugin \"" + plugin + "\" is not found.")); | ||
} | ||
@@ -64,2 +65,5 @@ | ||
new WebWorkerTemplatePlugin(workerOptions).apply(workerCompiler); | ||
new FetchCompileWasmTemplatePlugin({ | ||
mangleImports: compilerOptions.optimization.mangleWasmImports | ||
}).apply(workerCompiler); | ||
new SingleEntryPlugin(this.context, request, options.name).apply(workerCompiler); | ||
@@ -66,0 +70,0 @@ var subCache = "subcache " + __dirname + " " + request; |
{ | ||
"name": "worker-plugin", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "Webpack plugin to bundle Workers automagically.", | ||
@@ -5,0 +5,0 @@ "main": "dist/worker-plugin.js", |
@@ -65,4 +65,30 @@ <p align="center"> | ||
## Options & Plugins | ||
## Options | ||
In most cases, no options are necessary to use WorkerPlugin. | ||
### `globalObject` | ||
WorkerPlugin will warn you if your Webpack configuration has `output.globalObject` set to `window`, since doing so breaks Hot Module Replacement in web workers. | ||
If you're not using HMR and want to disable this warning, pass `globalObject:false`: | ||
```js | ||
new WorkerPlugin({ | ||
// disable warnings about "window" breaking HMR: | ||
globalObject: false | ||
}) | ||
``` | ||
To configure the value of `output.globalObject` for WorkerPlugin's internal Webpack Compiler, set `globalObject` to any String: | ||
```js | ||
new WorkerPlugin({ | ||
// use "self" as the global object when receiving hot updates. | ||
globalObject: 'self' // <-- this is the default value | ||
}) | ||
``` | ||
### `plugins` | ||
By default, `WorkerPlugin` doesn't run any of your configured Webpack plugins when bundling worker code - this avoids running things like `html-webpack-plugin` twice. For cases where it's necessary to apply a plugin to Worker code, use the `plugins` option. | ||
@@ -69,0 +95,0 @@ |
@@ -20,2 +20,3 @@ /** | ||
import WebWorkerTemplatePlugin from 'webpack/lib/webworker/WebWorkerTemplatePlugin'; | ||
import FetchCompileWasmTemplatePlugin from 'webpack/lib/web/FetchCompileWasmTemplatePlugin'; | ||
import WORKER_PLUGIN_SYMBOL from './symbol'; | ||
@@ -31,5 +32,8 @@ | ||
const compilerOptions = this._compiler.options || {}; | ||
if (!hasWarned && compilerOptions.output && compilerOptions.output.globalObject === 'window') { | ||
const pluginOptions = compilerOptions.plugins.find(p => p[WORKER_PLUGIN_SYMBOL]).options; | ||
if (pluginOptions.globalObject == null && !hasWarned && compilerOptions.output && compilerOptions.output.globalObject === 'window') { | ||
hasWarned = true; | ||
console.warn('Warning (workerize-loader): output.globalObject is set to "window". It should be set to "self" or "this" to support HMR in Workers.'); | ||
console.warn('Warning (worker-plugin): output.globalObject is set to "window". It must be set to "self" to support HMR in Workers.'); | ||
} | ||
@@ -42,6 +46,5 @@ | ||
chunkFilename, | ||
globalObject: 'self' | ||
globalObject: pluginOptions.globalObject || 'self' | ||
}; | ||
const pluginOptions = compilerOptions.plugins.find(p => p[WORKER_PLUGIN_SYMBOL]).options; | ||
const plugins = (pluginOptions.plugins || []).map(plugin => { | ||
@@ -53,3 +56,3 @@ if (typeof plugin !== 'string') { | ||
if (!found) { | ||
console.warn(`Warning (workerize-loader): Plugin "${plugin}" is not found.`); | ||
console.warn(`Warning (worker-plugin): Plugin "${plugin}" is not found.`); | ||
} | ||
@@ -61,2 +64,5 @@ return found; | ||
(new WebWorkerTemplatePlugin(workerOptions)).apply(workerCompiler); | ||
(new FetchCompileWasmTemplatePlugin({ | ||
mangleImports: compilerOptions.optimization.mangleWasmImports | ||
})).apply(workerCompiler); | ||
(new SingleEntryPlugin(this.context, request, options.name)).apply(workerCompiler); | ||
@@ -63,0 +69,0 @@ |
Sorry, the diff of this file is not supported yet
46034
342
121