CesiumGS / cesium-webpack-example

The minimal recommended setup for an application using Cesium with Webpack.
Apache License 2.0
243 stars 160 forks source link

Include loaders for binary files like glb and wasm #10

Open ggetz opened 6 years ago

ggetz commented 6 years ago

Brought up on the forum here: https://groups.google.com/forum/#!topic/cesium-dev/t463ShjMtEI

The new Draco wasm file needs to be loaded using a wasm loader.

Additionally, glb files and other binary files need to be loaded using an appropriate binary loader as well. Since it's so common to load these into a Cesium app, they should be included here.

nmschulte commented 6 years ago

I believe this is the same/related issue I was running into: https://groups.google.com/d/msg/cesium-dev/TPSOorUDU2Y/VJv3SOktAAAJ

I am currently updating this project to use Webpack 4 and Cesium 1.46 to reproduce and diagnose the issue. Does that forum post identify a solution?

nmschulte commented 6 years ago

I can no longer reproduce my issue with the latest versions of webpack (4.1.24.12.0) and various loaders (file-loader [0.11.21.1.11], url-loader [0.5.91.0.1]).

No matter if wasm-loader is in my "loader stack" (module loading rules; using oneOf w/ wasm-loader just before file-loader catch-all), this is what Webpack outputs

WARNING in ./node_modules/cesium/Source/ThirdParty/draco_decoder.wasm
Module parse failed: magic header not detected
You may need an appropriate loader to handle this file type.
Error: magic header not detected
    at new CompileError (/app/node_modules/@webassemblyjs/helper-api-error/lib/index.js:40:109)
    at parseModuleHeader (/app/node_modules/@webassemblyjs/wasm-parser/lib/decoder.js:288:13)
    at Object.decode (/app/node_modules/@webassemblyjs/wasm-parser/lib/decoder.js:1503:3)
    at decode (/app/node_modules/@webassemblyjs/wasm-parser/lib/index.js:234:21)
    at WebAssemblyParser.parse (/app/node_modules/webpack/lib/wasm/WebAssemblyParser.js:74:19)
    at doBuild.err (/app/node_modules/webpack/lib/NormalModule.js:462:32)
    at runLoaders (/app/node_modules/webpack/lib/NormalModule.js:344:12)
    at /app/node_modules/loader-runner/lib/LoaderRunner.js:370:3
    at iterateNormalLoaders (/app/node_modules/loader-runner/lib/LoaderRunner.js:211:10)
    at iterateNormalLoaders (/app/node_modules/loader-runner/lib/LoaderRunner.js:218:10)
    at /app/node_modules/loader-runner/lib/LoaderRunner.js:233:3
    at runSyncOrAsync (/app/node_modules/loader-runner/lib/LoaderRunner.js:130:11)
    at iterateNormalLoaders (/app/node_modules/loader-runner/lib/LoaderRunner.js:229:2)
    at Array.<anonymous> (/app/node_modules/loader-runner/lib/LoaderRunner.js:202:4)
    at Storage.finished (/app/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:43:16)
    at provider (/app/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:79:9)
 @ ./node_modules/cesium/Source/ThirdParty sync ^.\/.*$
 @ ./node_modules/cesium/Source/ThirdParty/xss.js
 @ ./node_modules/cesium/Source/Core/Credit.js
 @ ./node_modules/cesium/Source/Core/IonResource.js
 @ ./node_modules/cesium/Source/Core/createWorldTerrain.js
 @ ./src/index.js
 @ multi ./scripts/config/polyfills.js ./src/index.js

My application seems to run fine even with this warning. It is not using Draco, except unless the Ion provided terrain is using Draco.

Upgrading as I did required that I provide webpack with more heap space (node --max-old-space), and things take a bit longer to build, but it does work, even without wasm-loader.

tkazik commented 5 years ago

@nmschulte Would you mind sharing your webpack.config.js? I am currently getting the following error:

failed_to_load_model

Thank you!

nmschulte commented 5 years ago

@nmschulte Would you mind sharing your webpack.config.js?

@tkazik I can share a portion if you know what you're interested in.

Cronopaul commented 5 years ago

Hallo, I downloaded the cesium-webpack-example and I have the following error:

cesium.js:14947 GET http://localhost:8080/ThirdParty/draco_decoder.wasm 404 (Not Found)

I can share a portion if you know what you're interested in.

Can you please share the part with the wasm loader?

nmschulte commented 5 years ago

Can you please share the part with the wasm loader?

@Cronopaul, I mitigated/resolved my issue by using a newer version of Webpack; Switching from Webpack v4.2.0 to Webpack v4.12.0 led to my comment here: https://github.com/AnalyticalGraphicsInc/cesium-webpack-example/issues/10#issuecomment-396446402

To be clear, there is no wasm-loader in my Webpack config (webpack.config.js), I'm simply letting Webpack/file-loader handle these as they like.

Cronopaul commented 5 years ago

Thanks for your reply. I'm using Webpack v4.30.0.