GoogleChromeLabs / worker-plugin

👩‍🏭 Adds native Web Worker bundling support to Webpack.
https://npm.im/worker-plugin
Apache License 2.0
1.91k stars 79 forks source link

How to do the configuration change if I use react-scripts? #23

Closed bfang711 closed 5 years ago

bfang711 commented 5 years ago

I use react-scripts, not webpack. How to do the configuration change to use worker-plugin? I think I found the solution by adding

const WorkerPlugin = require('worker-plugin'); plugins:[ new WorkerPlugin({globalObject: 'self'}), ....]

into the node_modules/react-scripts/config/webpack.config.js file. Now seems like the worker.js can be bundled and automatically compiled. However I met the compiling error when compile the following worker.js file.

Line 2: Unexpected use of 'addEventListener' no-restricted-globals

in worker.js

import answer from './answer';

addEventListener('message',function(e){ console.log("WORKER data ",e.data); postMessage("123 123 abc abc"); });

What am I missing here?

thanks