threads-plugin
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -70,7 +70,7 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
var loaderOptions = opts.name && { | ||
name: opts.name | ||
var loaderOptions = { | ||
name: opts.name || workerId + '' | ||
}; | ||
var req = "require(" + (JSON.stringify(workerLoader + (loaderOptions ? '?' + JSON.stringify(loaderOptions) : '') + '!' + dep.string)) + ")"; | ||
var id = "__webpack__worker__" + (++workerId); | ||
var req = "require(" + (JSON.stringify(workerLoader + '?' + JSON.stringify(loaderOptions) + '!' + dep.string)) + ")"; | ||
var id = "__webpack__worker__" + (workerId++); | ||
ParserHelpers.toConstantDependency(parser, id)(expr.arguments[0]); | ||
@@ -85,3 +85,3 @@ ParserHelpers.addParsedVariableToModule(parser, id, req); | ||
compilation.warnings.push({ | ||
message: 'No instantiations of threads.js workers found. ' + 'Make sure you have configured Babel / TypeScript to not transpile ES modules, so webpack can do that.' | ||
message: 'No instantiations of threads.js workers found.\n' + 'Please check that:\n' + ' 1. You have configured Babel / TypeScript to not transpile ES modules\n' + ' 2. You import `Worker` from `threads` where you use it\n\n' + 'For more details see: https://github.com/andywer/threads-plugin\n' | ||
}); | ||
@@ -88,0 +88,0 @@ } |
{ | ||
"name": "threads-plugin", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Webpack plugin to bundle threads.js workers automagically.", | ||
@@ -34,3 +34,3 @@ "main": "dist/threads-plugin.js", | ||
"<rootDir>/node_modules/", | ||
"<rootDir>/test/fixtures/.*?/dist/" | ||
"<rootDir>/test/fixtures/" | ||
] | ||
@@ -67,2 +67,5 @@ }, | ||
"devDependencies": { | ||
"@file-services/memory": "^1.0.3", | ||
"@file-services/node": "^1.0.3", | ||
"@file-services/overlay": "^1.0.3", | ||
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.2", | ||
@@ -69,0 +72,0 @@ "clean-webpack-plugin": "^1.0.0", |
<p align="center"> | ||
<img src="https://i.imgur.com/MlrAQjl.jpg" width="1000" alt="worker-plugin"> | ||
</p> | ||
<p></p> | ||
<h1 align="center">👩🏭 threads-plugin</h1> | ||
<p align="center">Automatically bundle & compile <a href="https://github.com/andywer/threads.js">threads.js</a> workers within webpack.</p> | ||
### Fork of [worker-plugin](https://github.com/GoogleChromeLabs/worker-plugin) | ||
This plugin is a fork of [worker-plugin](https://github.com/GoogleChromeLabs/worker-plugin): This is an adapted version of the original `worker-plugin` that supports `Worker` constructors imported from [`threads`](https://github.com/andywer/threads.js). | ||
This is an adapted version of the original `worker-plugin` that supports `Worker` constructors imported from [`threads`](https://github.com/andywer/threads.js). | ||
### Features | ||
@@ -72,2 +71,4 @@ | ||
**Please make sure to use the `Worker` imported from `threads`, not the global `Worker`! The plugin will only consider those imported `Worker` instantiations.** | ||
## Babel / TypeScript | ||
@@ -77,4 +78,6 @@ | ||
In your Babel configuration: | ||
### Babel | ||
In your Babel configuration when using `@babel/preset-env`: | ||
``` | ||
@@ -88,4 +91,10 @@ "presets": [ | ||
When using TypeScript: | ||
If you are using `create-react-app` or `babel-preset-react-app` (`"presets": ["react-app"]`), you are already good to go - no need to adapt the configuration. | ||
So the idea is to make sure that ES modules are still intact and not transpiled down to anything else by Babel. Otherwise the plugin won't work. This kind of configuration is best practice anyhow. | ||
### TypeScript | ||
When using TypeScript, make sure this setting is part of your TypeScript configuration, either in the `ts-loader` options or in your `tsconfig.json` file: | ||
``` | ||
@@ -92,0 +101,0 @@ "compilerOptions": { |
@@ -72,5 +72,5 @@ /** | ||
let loaderOptions = opts.name && { name: opts.name }; | ||
const req = `require(${JSON.stringify(workerLoader + (loaderOptions ? ('?' + JSON.stringify(loaderOptions)) : '') + '!' + dep.string)})`; | ||
const id = `__webpack__worker__${++workerId}`; | ||
const loaderOptions = { name: opts.name || workerId + '' }; | ||
const req = `require(${JSON.stringify(workerLoader + '?' + JSON.stringify(loaderOptions) + '!' + dep.string)})`; | ||
const id = `__webpack__worker__${workerId++}`; | ||
ParserHelpers.toConstantDependency(parser, id)(expr.arguments[0]); | ||
@@ -88,4 +88,7 @@ | ||
message: | ||
'No instantiations of threads.js workers found. ' + | ||
'Make sure you have configured Babel / TypeScript to not transpile ES modules, so webpack can do that.' | ||
'No instantiations of threads.js workers found.\n' + | ||
'Please check that:\n' + | ||
' 1. You have configured Babel / TypeScript to not transpile ES modules\n' + | ||
' 2. You import `Worker` from `threads` where you use it\n\n' + | ||
'For more details see: https://github.com/andywer/threads-plugin\n' | ||
}) | ||
@@ -92,0 +95,0 @@ } |
@@ -59,2 +59,3 @@ /** | ||
const workerCompiler = this._compilation.createChildCompiler(NAME, workerOptions, plugins); | ||
workerCompiler.context = this._compiler.context; | ||
(new WebWorkerTemplatePlugin(workerOptions)).apply(workerCompiler); | ||
@@ -61,0 +62,0 @@ (new FetchCompileWasmTemplatePlugin({ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
341375
4068
159
17