Giter Club home page Giter Club logo

Comments (7)

Pauan avatar Pauan commented on May 30, 2024 4

@marienz You should be able to workaround the Webpack loading issue by doing this.

I think it would be a good idea for us to include some documentation on how to use wasm-bindgen with Angular.

from wasm_game_of_life.

marienz avatar marienz commented on May 30, 2024 2

Got it to work in Angular 8 (without resorting to no-modules) by using @angular-builders/custom-webpack. The only thing I had to put in extra-webpack.config.js was module.exports = {'resolve': {'extensions': ['.wasm']}}; (I suspect if we get that added here it'll work out of the box).

One slight annoyance is that just importing the wasm-bindgen-generated module triggers a "WebAssembly module is included in initial chunk" error. I guess that's webpack/webpack#6615. Using import() to import the wasm-bindgen module (as suggested by the error message) does work. And I suspect if my import was in a lazily-loaded Angular module that'd also work around it, but I'm barely past "Hello World" in Angular... don't want to try breaking my app into modules before I've actually gotten it to work :)

(It also warns about the circular dependency between the wasm module and the generated js module, I think that's the same thing described on rustwasm/wasm-bindgen#32 and I'll just have to ignore it.)

from wasm_game_of_life.

fitzgen avatar fitzgen commented on May 30, 2024

Does angular use its own bundler or something? I'm not sure what is different about it compared to normal JS applications.

You can always use the web or no-modules target and include a <script> before the rest of your app, and use the wasm library from the global scope.

https://rustwasm.github.io/docs/wasm-bindgen/examples/without-a-bundler.html

from wasm_game_of_life.

mokeyish avatar mokeyish commented on May 30, 2024

@fitzgen Thank you, I have solved it by following your advice.

from wasm_game_of_life.

suyoshi avatar suyoshi commented on May 30, 2024

This is why it does not work with Angular out of the box:
rustwasm/wasm-bindgen#806

Altough I have no idea how to add this extension to the angular.json and using no-modules is not the best solution. 😞

from wasm_game_of_life.

marienz avatar marienz commented on May 30, 2024

angular/angular-cli#14987 was opened a few days ago for getting that extension added in Angular.

from wasm_game_of_life.

marienz avatar marienz commented on May 30, 2024

That's a trick I wouldn't have thought of, thanks!

from wasm_game_of_life.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.