Skip to content

Commit 1b3f3d1

Browse files
authored
Merge pull request #3 from andywer/feature/2-improve-usability
Improve error wording and readme a bit
2 parents 63b8ec1 + 075ec75 commit 1b3f3d1

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

README.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
<p align="center">
22
<img src="https://i.imgur.com/MlrAQjl.jpg" width="1000" alt="worker-plugin">
33
</p>
4+
<p></p>
45
<h1 align="center">👩‍🏭 threads-plugin</h1>
56
<p align="center">Automatically bundle & compile <a href="https://github.com/andywer/threads.js">threads.js</a> workers within webpack.</p>
67

7-
### Fork of [worker-plugin](https://github.com/GoogleChromeLabs/worker-plugin)
8-
9-
This is an adapted version of the original `worker-plugin` that supports `Worker` constructors imported from [`threads`](https://github.com/andywer/threads.js).
8+
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).
109

1110
### Features
1211

@@ -69,11 +68,15 @@ async function main() {
6968
}
7069
```
7170

71+
**Please make sure to use the `Worker` imported from `threads`, not the global `Worker`! The plugin will only consider those imported `Worker` instantiations.**
72+
7273
## Babel / TypeScript
7374

7475
When transpiling your source code using Babel or TypeScript, make sure to that ES modules are transpiled by webpack, not by Babel or TypeScript. Otherwise the threads plugin won't be able to identify the imports.
7576

76-
In your Babel configuration:
77+
### Babel
78+
79+
In your Babel configuration when using `@babel/preset-env`:
7780

7881
```
7982
"presets": [
@@ -83,7 +86,13 @@ In your Babel configuration:
8386
]
8487
```
8588

86-
When using TypeScript:
89+
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.
90+
91+
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.
92+
93+
### TypeScript
94+
95+
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:
8796

8897
```
8998
"compilerOptions": {

src/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,11 @@ export default class WorkerPlugin {
8484
if (workerId === 0) {
8585
compilation.warnings.push({
8686
message:
87-
'No instantiations of threads.js workers found. ' +
88-
'Make sure you have configured Babel / TypeScript to not transpile ES modules, so webpack can do that.'
87+
'No instantiations of threads.js workers found.\n' +
88+
'Please check that:\n' +
89+
' 1. You have configured Babel / TypeScript to not transpile ES modules\n' +
90+
' 2. You import `Worker` from `threads` where you use it\n\n' +
91+
'For more details see: https://github.com/andywer/threads-plugin\n'
8992
})
9093
}
9194
})

0 commit comments

Comments
 (0)