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

Using planck in a webworker #160

Open
zjeff222 opened this issue Jan 27, 2021 · 8 comments
Open

Using planck in a webworker #160

zjeff222 opened this issue Jan 27, 2021 · 8 comments

Comments

@zjeff222
Copy link

zjeff222 commented Jan 27, 2021

I don't know anything about webpack but it seams to be blocking planck from loading into a web worker. There is an access to the window element, which is not defined in a worker, and it really seams to be webpack related.

So I replaced the "window" reference to "this" and it works, but I really don't know what I'm doing!

@shakiba
Copy link
Collaborator

shakiba commented Jan 28, 2021

Might be related to this: webpack/webpack#6525

@zjeff222
Copy link
Author

Just to be clear, I was talking about the webpack code embeded in planck.js. So I edited line 34 of the planck.js file. Patching the library will do for me for now. It's great to have box2d on javascript by the way :)

@shakiba
Copy link
Collaborator

shakiba commented Jan 30, 2021

Could you please try the solution described in this and this comments?

@zjeff222
Copy link
Author

zjeff222 commented Jan 30, 2021

If I understand, this would be a solution where I am to use webpack. I'm not using webpack. So if I do understand, some webpack code is added to planck.js to make it better for those who use webpack ? I only used 2-3 libraries up to now and it's the first one I see with embeded webpack code. (I'm new to js)

@shakiba
Copy link
Collaborator

shakiba commented Jan 30, 2021

Webpack combines source files and generates files like planck.js file, Planck distribution files are built with webpack. We need to configure webpack to fix the issue that you reported in the build file.

@shakiba
Copy link
Collaborator

shakiba commented Jan 30, 2021

Oh, what I meant by asking if that solution works for you was that if rebuilding planck with that solution will solve the problem. I did not mean to use that solution in your project.

@zjeff222
Copy link
Author

Sorry, I don't want to learn how to build a js library at this time. If you want to reproduce the problem, you only have to call a worker with myWorker = new Worker('./worker.js');
and in the worker.js import planck: importScripts('../../lib/planck.min.js');

@shakiba
Copy link
Collaborator

shakiba commented Jan 31, 2021

Makes sense, no worries; if you need to build it for any other reason here are the commands (assuming git and npm are already installed):

git clone [email protected]:shakiba/planck.js.git
cd planck.js
npm install
npm run build

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

2 participants