You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+22Lines changed: 22 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -76,6 +76,28 @@ const MyComponent = () => (
76
76
)
77
77
```
78
78
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
+
importWebWorkerfrom"react-webworker"
87
+
88
+
constmyWorker=newWorker("./worker.js") // relative path to the source file, not the public URL
89
+
90
+
constMyComponent= () => (
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.
0 commit comments