Skip to content

Commit 236224d

Browse files
authored
Add usage details for Parcel and worker-plugin.
1 parent 33cec1f commit 236224d

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,28 @@ const MyComponent = () => (
7676
)
7777
```
7878

79+
### Usage with Parcel or `worker-plugin` for Webpack
80+
81+
[Parcel](https://parceljs.org) and [worker-plugin](https://npm.im/worker-plugin) allow your Web Worker script to be
82+
automatically bundled. However this only works when you create the Worker instance yourself, instead of having react-webworker
83+
do it for you. Here's how that works:
84+
85+
```js
86+
import WebWorker from "react-webworker"
87+
88+
const myWorker = new Worker("./worker.js") // relative path to the source file, not the public URL
89+
90+
const MyComponent = () => (
91+
<WebWorker worker={myWorker}>
92+
...
93+
</WebWorker>
94+
)
95+
```
96+
97+
The downside to this approach is that `<WebWorker>` will not manage the Worker's lifecycle. This means it will not automatically be terminated when `<WebWorker>` is unmounted.
98+
99+
## API
100+
79101
### Props
80102

81103
`<WebWorker>` takes the following properties:

0 commit comments

Comments
 (0)