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

not working with create-react-app #1

Open
Ognian opened this issue Nov 14, 2019 · 11 comments
Open

not working with create-react-app #1

Ognian opened this issue Nov 14, 2019 · 11 comments

Comments

@Ognian
Copy link

Ognian commented Nov 14, 2019

Unfortunately this doesn't work with webpack (create-react-app). Any plans to support this?
Thanks
Ognian

@pocesar
Copy link
Owner

pocesar commented Nov 15, 2019

I have no experience with CRA, is it giving any error at all?

or what makes common libraries not compatible with CRA, and what should be done to work with it?

@Ognian
Copy link
Author

Ognian commented Nov 15, 2019

CRA uses webpack, webpack combines all sources into ONE js file BUT the worker.js is a separate file and so the journey starts...
I tried with some simple tricks to work around the first error messages but it goes deeper and deeper, so I gave up...

@pocesar
Copy link
Owner

pocesar commented Nov 15, 2019

oh, I see... well, I thought webpack worked like Parcel, that inlines the worker file and puts it inside the file as a blob url, since it only makes sense in this scenario as in a one-file bundle. but since I have no idea how CRA is configured or if it can be extended, I could only guess that a post-compilation would have to be made to make the patching (the inlining) in the generated file.

@Ognian
Copy link
Author

Ognian commented Nov 16, 2019

webpack needs at least some kind of import statement to inline the code, but Comlink is called with a string...

@pocesar
Copy link
Owner

pocesar commented Nov 17, 2019

I see, although that's not the defacto way for working with workers, the proper way to initialize them is using new Worker('path'), and not import, so webpack is on the err side here

@Ognian
Copy link
Author

Ognian commented Nov 17, 2019

OK, looks like there is this...
But the problem is if there is a way to let CRA do this without ejecting...

@pocesar
Copy link
Owner

pocesar commented Nov 17, 2019

what do you mean by "without ejecting"?

@Ognian
Copy link
Author

Ognian commented Nov 18, 2019

CRA manages webpack and babel settings. When you "eject" you remove CRA and can manage all the settings...
Normally you do not want to "eject" since CRA gives you an easier way to upgrade...
So most people want a way to use a react lib with CRA without "ejecting"

@pocesar
Copy link
Owner

pocesar commented Nov 18, 2019

according to the worker-plugin then, I would have to put { type: 'module' } to the Worker instantiation and would work? or am I missing something? or it's not possible to configure anything without ejecting? (sorry about the silly questions, but I never ever used CRA before)

@Ognian
Copy link
Author

Ognian commented Nov 18, 2019

Looks like something like this could be the way to go....
At the moment I don't have time to evaluate it, maybe later...

@TheForsakenSpirit
Copy link

@Ognian CRA protect config of webpack from changing...
Depend on my experience with service worker, you can write node script for compiling webworker with separate call of webpack or copy ready to use webworker file to public folder and set path to them.
Will work only for build, but can help avoid eject.

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

3 participants