Webpack + workers


#1

I’ve tested a worker which works well, however I cannot load it correctly using Webpack. I’m trying to use https://github.com/NativeScript/worker-loader and follow the instructions but no success.

Is there a working sample for workers that actually works with Webpack?

I’m using Nativescript + Angular, any help will be appreciated.


#2

You also need to use the @next of the android-runtime, or wait for the 3.2 release.

But that’s just an assumption, would you explain what isn’t working correctly?

Also, Stanimira’s got a demo app where she tested the worker loader - https://github.com/sis0k0/webpack-worker


#3

Thanks Pete. Stanimira’s demo is not really a working sample since it doesn’t call the worker or getting anything back from it. Once you add the necessary calls and callbacks it is does not work (either using webpack or not).

I’ve enhanced the demo and made it work for the non-webpack version, but it is not compiling with webpack. I would be very happy to see a working webpack sample.

Compiling with webpack I get an error (running the static binding generator):


Running full build
finished with reading lines with js files
Warning: there already is an extend called com.tns.FragmentClass.
Warning: The static binding generator will generate extend from:vendor.js implementation
Warning: there already is an extend called com.tns.FragmentClass.
Warning: The static binding generator will generate extend from:cee216722ea55df5fcae.worker.js implementation
Warning: there already is an extend called com.tns.FragmentClass.
Warning: The static binding generator will generate extend from:e9e6fe21080fa2a8cfbf.worker.js implementation
:asbg:generateBindings
Exception in thread "main" java.io.IOException: File already exists. This may lead to undesired behavior.
Please change the name of one of the extended classes.
File:G:\Dropbox\Live\NS\webpack-worker\platforms\android\src\main\java\com\tns\FragmentClass.java Class: com.tns.FragmentClass
        at org.nativescript.staticbindinggenerator.Generator.writeBindings(Generator.java:68)
        at org.nativescript.staticbindinggenerator.Main.main(Main.java:15)
:asbg:generateBindings FAILED

FAILURE: Build failed with an exception.

* Where:
Build file 'G:\Dropbox\Live\NS\webpack-worker\platforms\android\build-tools\android-static-binding-generator\build.gradle' line: 254

* What went wrong:
Execution failed for task ':asbg:generateBindings'.
> Process 'command 'C:\Program Files\Java\jdk1.8.0_102\bin\java.exe'' finished with non-zero exit value 1

#4

Did you install the latest android runtime (@next)?


#5

In Stanimira’s demo I used whatever she put in package.json which is ver: 3.2.0-next-2017-06-28-1901

In my own project I’ve used 3.2.0-2017-8-22-1.

I’ll try to update her demo with the latest later on and let you know.


#6

Yes it works.

I also noticed the ts worker files were not transpiled for some reason, this was part of the whole issue. With the correct js files and the @next version my app works too.

Thank you very much!