CodeSerializer Can't serialize code for OBJLoader2Parallel worker correctly when threejs is bundled with webpack
See original GitHub issueDescription of the problem
I’m using Threejs in a project with webpack to bundle the code. When I’m trying to use the OBJLoader2Parallel class to load obj files in a web worker, But it failed due to undefined webpack code utils_ObjectManipulator_js__WEBPACK_IMPORTED_MODULE_0_ in the worker code.
After some investigation, I find out that the worker code are generated on the fly using CodeSerializer based on code like WorkerRunner.js, ObjectManipulator.js and OBJLoader2Parser.js, which are all bundled into the same bundle file by webpack.
But due to ObjectManipulator.js is imported to WorkerRunner.js file, the code below:
ObjectManipulator.applyProperties( parser, payload.params );
in WorkerRunner.js will be converted to:
_utils_ObjectManipulator_js__WEBPACK_IMPORTED_MODULE_0__["ObjectManipulator"].applyProperties( parser, payload.params );
by webpack.
Then, when the OBJLoader2Parallel is building the worker code with CodeSerializer, the code above will be copied directly and it can’t resolve utils_ObjectManipulator_js__WEBPACK_IMPORTED_MODULE_0_[“ObjectManipulator”] to the ObjectManipulator object. This makes the worker fail.
Three.js version
- Dev
- r109
- …
Browser
- All of them
- Chrome
- Firefox
- Internet Explorer
OS
- All of them
- Windows
- macOS
- Linux
- Android
- iOS
Hardware Requirements (graphics card, VR Device, …)
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (5 by maintainers)
Top GitHub Comments
I’ve set up a test repo at https://github.com/geoff-harper/obj-parallel-cra-test. I can’t speak to CRA’s minification process but you can
yarn eject
to see their webpack config. It looks like they’re using https://github.com/terser/terser under the hoodThanks! @kaisalmen