Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webworkers? #1655

Closed
bmayen opened this issue Mar 30, 2017 · 16 comments
Closed

Webworkers? #1655

bmayen opened this issue Mar 30, 2017 · 16 comments

Comments

@bmayen
Copy link

bmayen commented Mar 30, 2017

Has anybody had any success getting webworkers to work in this repo?

@bmayen
Copy link
Author

bmayen commented Mar 30, 2017

I've added another entry point for my worker bundle. In main.browser.ts I load the worker via bootloader(bootstrapWorkerUi('worker.bundle.js')). This works but I get webpackJsonpac__name_ is not defined thrown from the worker bundle at runtime. The problem as I understand it is that the webpack manifest sets up some methods on window and these are not available to the webworker.

Would duplicating the webpack manifest in the worker bundle fix this? Any ideas on how to do that?

@tobek
Copy link
Contributor

tobek commented Mar 31, 2017

I got it to work using worker-loader and then calling it like so:

const WorkerLoader = require('worker-loader?name=name-of-output-file.[hash].js!path/to/your/worker.ts');
const worker = new WorkerLoader();
worker.onmessage = ...

I didn't have to modify any of the config files, and the build automagically creates built JS file replacing [hash] with content-dependent hash in it (e.g. name-of-output-file.1234567890abcdef.js).

However, if you want to split out common chunks between the worker and your main scripts (e.g. loading a vendor bundle from within the worker with importScripts()) then it's more complicated and will involve updating the configs and I'd love to know what you come up with! I couldn't get that part to work.

@bmayen
Copy link
Author

bmayen commented Apr 4, 2017

Thanks @tobek. I'll try out this approach this week and report back.

@bmayen
Copy link
Author

bmayen commented Apr 9, 2017

While this will work if you are using webworkers directly as in you example, it won't work with Angular's webworker strategy. Looking into https://github.com/shlomiassaf/angular-worker-loader for this, but one of the listed TODOs is "Workflow with bundles, especially hashed", so this might be a non-starter for me.

@bmayen
Copy link
Author

bmayen commented Apr 14, 2017

@ghost
Copy link

ghost commented May 3, 2017

@bmayen you solved this problem?

@bmayen
Copy link
Author

bmayen commented May 3, 2017

Basically used the approach described in the stackoverflow link I posted. Our company is currently working on a contribution to Angular-CLI to support webworkers out of the box there, so that's where our focus is now. General principles should work with this starter though as well.

@jt-helsinki
Copy link

@bmayen How your team go with this? Did you manage to successfully submit the contribution to the Angular-Cli project?

@bmayen
Copy link
Author

bmayen commented Jul 28, 2017

This approach is not the one preferred by the Angular-CLI team, so we never submitted a PR for it. There's an open issue for it but it is only prioritized as a "nice-to-have". I've requested higher priority but it hasn't gotten traction yet. angular/angular-cli#2305

@Gromov-Roman
Copy link

@bmayen Good day! Did you manage to introduce web workers into this repo??? Can you get me example or solution of it?

@adrian-mitangi
Copy link

I'd also like to see this happen.

@bmayen
Copy link
Author

bmayen commented Aug 7, 2017

@KhanaevRoman, I followed the example in the link above

@Gromov-Roman
Copy link

@bmayen shlomiassaf solution? But it is not this repo based project...

@bmayen
Copy link
Author

bmayen commented Aug 9, 2017

Basically used the approach described in the stackoverflow link I posted. Our company is currently working on a contribution to Angular-CLI to support webworkers out of the box there, so that's where our focus is now. General principles should work with this starter though as well.

@yzhe554
Copy link

yzhe554 commented Oct 4, 2017

@bmayen Can I ask how did you get rid of 'window is undefined' error message with the solution in the stackoverflow link?

@bmayen
Copy link
Author

bmayen commented Oct 4, 2017

Would need more information. That error could be caused by any number of things. What does the error stack look like?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants