Where can one publish the wasm files to be used on Ruby on Rails projects? #812
-
The deploy and publish guide seems to suggest that you need an ASP.NET project. My situation is different:
Any pointers would be much appreciated. chrs |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 11 replies
-
I could be missing the mark on what you're trying to accomplish, but hopefully this will clear a few things up. There's not any special server side requirements because the files don't run server side, and are downloaded like regular file downloads, i.e. static file hosting. There's really no need for a ASP.NET host. For example I have a WASM bootstrap demo running in Github.io which is nothing but a static file host with no server side code. See https://serratedsharp.github.io/CSharpWasmJQueryDemo/ and note in network tab of browser console the *.clr WASM files being downloaded. I think it's similar to your request in that I have a LuhnCheckDigit calculation implemented in .NET WASM that is called from Javascript on the page. I just took the output of /MyProject/bin/Release/net8.0/dist/ and copied it up to the server. If Ruby on rails can serve static files like css/images/JS, then it should be able to serve the WASM package files. You may need to configure mimetypes for "*.clr" as "application/octet-stream" and ".dat" as "application/dat" to allow your web server to serve them. Often web hosts will block downloads of any unknown file extensions until you do whatever is necessary for that web host to add the mimetypes. To be clear, nothing executes until the WASM package is downloaded to the browser and Uno bootstrap initializes your assembly. Akin to a javascript file being downloaded and executed in the browser. All of the output in bin/Release/dist/ (short for "distribution") are the static files needed, mine might look slightly different as I am using EmebddedMode: Using the default build, when you access index.html, the browser will load the page, and Uno bootstrap will run and locate the other assets and then execute your WASM Program Main entry point inside the browser. So just like you might have a /scripts/ folder on your web server for javascript files, you could create a /wasm/ folder and copy everything from /dist/ into it. When you navigate to yoururl.com/dist/index.html the WASM will load and execute. The index.htm is basically a blank page that runs your WASM as if it were a skeleton for a SPA/single page application. It doesn't integrate in any way with your web application. So serving the package is the easy part. Getting the WASM to execute in the same context as whatever other web application code you're wanting to integrate it with is the complicated part. I would guess what you want to do is from some of your existing client side javascript running inside existing pages of your Ruby on rails app, you want to call a method in your .NET WASM module(which you exported using something like So maybe you have an computationally intensive CalculateChecksum() function in .NET WASM exported, and whenever someone clicks a button on your ruby rails app, then some javascript button handler runs and you want that javascript to call the CalculateChecksum() function and get the return value. I don't think those details matter, but to put in concrete terms, your javascript and the WASM need to run on the same page. There's several ways to accomplish this, but one way is to use EmbeddedMode switch in your .NET console project that uses Uno.Bootstrap to build to WASM, so adding this to the *.csproj: <PropertyGroup>
<!-- Generate embedded.js -->
<WasmShellMode>BrowserEmbedded</WasmShellMode>
</PropertyGroup> This changes the output of /dist/ slightly, and includes a embedded.js. Now from your own application's HTML/JS, you can include this embedded.js assuming you've hosted the dist files on your web server: <script src="/dist/embedded.js"></script>
<script src="/js/yourexisting.js"></script> You could adjust the URL to an external host if for some reason it's necessary When embedded.js executes it will look for or create a and run a loading bar/splash screen while the WASM initializes, then load your assembly and call your Program.cs Main entry point. Now your [JSExport]'d .NET method should be available for your javascript to call and retrieve whatever it returns.https://platform.uno/docs/articles/external/uno.wasm.bootstrap/doc/features-embedded.mode.html Note they tell you to declare a div uno-body, but I have always found this results in two duplicate uno body's (mine and an additional one created by embedded.js). If you are calling the WASM module on demand, such as a triggered by a button click, then great. If you have some of your own javascript that tries to execute immediately upon page load and wants to call the WASM module immediately, it gets a little more complicated because it takes a moment for initialization and the WASM module might not be "ready" if you try to call it during page load. |
Beta Was this translation helpful? Give feedback.
I could be missing the mark on what you're trying to accomplish, but hopefully this will clear a few things up.
There's not any special server side requirements because the files don't run server side, and are downloaded like regular file downloads, i.e. static file hosting. There's really no need for a ASP.NET host. For example I have a WASM bootstrap demo running in Github.io which is nothing but a static file host with no server side code. See https://serratedsharp.github.io/CSharpWasmJQueryDemo/ and note in network tab of browser console the *.clr WASM files being downloaded. I think it's similar to your request in that I have a LuhnCheckDigit calculation implemented in .NET WASM that…