webpack-contrib / worker-loader

A webpack loader that registers a script as a Web Worker
MIT License
1.46k stars 273 forks source link

How can I import a library in worker? #331

Open RachelCT1 opened 3 years ago

RachelCT1 commented 3 years ago

I am new in web worker. I want to find out whether I can use library or module in worker? I have tried to use import xxx, but I get "show3d.worker.js:1 Uncaught SyntaxError: Cannot use import statement outside a module". My code like this: ` <!DOCTYPE HTML>

and the show3d.worker.js like this:

import * as THREE from "three"

//importScripts('https://unpkg.com/d3-force-3d')

onmessage =function (evt){

var d = evt.data;

console.log("get data:",d);

postMessage( "return test data" );

}

` I also tried "importScripts", but I can't get the library.

Thank you very much if you can give me some suggesions.