NativeScript / worker-loader

36 stars 20 forks source link

[Quick question] How would you use this loader with the nativescript-plugin-seed? #31

Open larssn opened 5 years ago

larssn commented 5 years ago

So we're trying to create a plugin that uses workers.

Am I correct in assuming that it would only work if the plugin is built with Webpack (and worker-loader), IF the consuming application is also built with Webpack?

I can't figure out how webpack in some-appwould try to resolve a relative path inside node_modules/some-plugin that points to a worker.ts/js file.

triniwiz commented 5 years ago

I've done it in the past https://github.com/TeamHive/nativescript-pspdfkit/blob/master/src/android/pspdfkit.ts#L50-L55

juanchinovas commented 4 years ago

I'm trying to load a worker from my nativescript plugin with no succed. I did the same as @triniwiz did

if (global["TNS_WEBPACK"]) {
 var UploaderWorker = require('nativescript-worker-loader!./google-drive.worker');
 config.worker = new UploaderWorker();
} else {
   config.worker = new Worker('./google-drive.worker');
}

nativescript-worker-loader works perfectly in a core or Angular app, but it's not works inside the plugin, I'm getting this error "Error: Cannot find module 'nativescript-worker-loader!./google-drive.worker'".

I'm using NativeScript v6.

{
 "platforms": {
    "android": "6.0.0",
    "ios": "6.0.1"
 }
}