Giter VIP home page Giter VIP logo

create-wasm-app's Introduction

create-wasm-app

An npm init template for kick starting a project that uses NPM packages containing Rust-generated WebAssembly and bundles them with Webpack.

Build Status

Built with ๐Ÿฆ€๐Ÿ•ธ by The Rust and WebAssembly Working Group

About

This template is designed for depending on NPM packages that contain Rust-generated WebAssembly and using them to create a Website.

๐Ÿšด Usage

npm init wasm-app

๐Ÿ”‹ Batteries Included

  • .gitignore: ignores node_modules
  • LICENSE-APACHE and LICENSE-MIT: most Rust projects are licensed this way, so these are included for you
  • README.md: the file you are reading now!
  • index.html: a bare bones html document that includes the webpack bundle
  • index.js: example js file with a comment showing how to import and use a wasm pkg
  • package.json and package-lock.json:
  • webpack.config.js: configuration file for bundling your js with webpack

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

create-wasm-app's People

Contributors

aaronabramov avatar alexcrichton avatar ashleygwilliams avatar dependabot-preview[bot] avatar dependabot-support avatar fitzgen avatar hskang9 avatar jimskapt avatar sendilkumarn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

create-wasm-app's Issues

This module doesn't work with `yarn create`

Describe the Bug

The yarn equivalent for npm init wasm-app www is `yarn create wasm-app www', but it doesn't work with this module.

Steps to Reproduce

  1. mkdir blah
  2. cd blah
  3. yarn create wasm-app www
  4. See error

Expected Behavior

The www directory gets created like when I run npm init wasm-app www.

Actual Behavior

Here's my output:

wt@XXXXXXX:~/projects/blah$ yarn create wasm-app www
yarn create v1.22.4
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Installed "[email protected]" with binaries:
      - create-wasm-app
/bin/sh: 1: /home/wt/.yarn/bin/create-wasm-app: not found
error Command failed.
Exit code: 127
Command: /home/wt/.yarn/bin/create-wasm-app
Arguments: www
Directory: /home/wt/projects/blah
Output:

info Visit https://yarnpkg.com/en/docs/cli/create for documentation about this command.

Additional Context

I was following the project tutorial except that I wanted to use yarn.

Minimum Node version

Summary

Going through the rustwasm book's Hello world, I was unable to generate the www directory with the suggested command:

npm init wasm-app www

This command generates a package.json file but not the www directory, as in rustwasm/book#174 .

Upgrading to Node 12 seemed to solve the issue. My question is if this behavior is expected for the node version I was using (v8.10.0) and, if so, what is the minimum version that produces the desired directory as in the the rustwasm book?

Additional Details

OS: Ubuntu 18.04.4.

express with wasm

I'm trying your example integrate into my application written with using express framework but get error in browser(Firefox v.60)
"Loading failed for module with source โ€œhttp://localhost:3000/public/javascripts/bootstrap.jsโ€
html:
"

<title>Hello wasm-pack!</title> <script type="module" src="../public/javascripts/bootstrap.js"></script> "

In Folder public/javascript next files unchanged as an example:
bootstrap.js
HelloWasm_bg.wasm
HelloWasm.d.ts
HelloWasm.js
index.js

WebAssembly is cool!!!Help me!

Validate whether if Git is installed in advance

Motivation

The utility assumes git is already installed and fails miserably if that is not the case (throws an error).

Proposed Solution

IMO, it is good to validate the respective case upfront and warn appropriately.

Alternatives

N/A

Additional Context

N/A

This module doesn't work anymore

I mean it dependencies have updated A lot and there are many breaking changes

webpack              ^4.29.3  โ†’  ^5.74.0
webpack-cli           ^3.1.0  โ†’  ^4.10.0
webpack-dev-server    ^3.1.5  โ†’  ^4.11.1

I guess you shouldn't have used webpack then ๐Ÿ˜
simply use --target web I suppose.

Tutorial issue section 4.4

Rust newbie here,
Just following the tutorial and I've reached midway through section 4.4 where I've run into a weird issue. I try building the project and running npm run start, that's when I got the error message:
ERROR in ./index.js 1:20
Module parse failed: Unexpected token (1:20)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders

import { Universe } as wasm from "wasm-game-of-life";
| const pre = document.getElementById("game-of-life-canvas");
| const universe = Universe.new();
@ ./bootstrap.js 4:0-20

How would I fix this issue?

Which is better performant for rust-wasm?

I'm trying to build a custom language code ditor with linting, syntax check etc.,

My opinon is to use rustwasm/web_sys crate to build and manage dom from rust. But on the initial few run Native JS dom binding seems to be performing better than rustwasm.

Do you have any performance metics comparing web_sys and native js?

[cloning template failed] npm init wasm-app

I just tried to create an instance of create-wasm-app by executing npm init wasm-app.
I was expecting the project initialization to succeed.
Instead, I got this error log:

~/Development/accept ๎‚ฐ npm init wasm-app
npx: installed 1 in 2.048s
cloning the template failed!

`npm init wasm-app www` fails

Describe the Bug

npm init wasm-app www fails.

Versions

>node --version
v20.16.0
>npm --version
10.8.2

Error

>npm init wasm-app www
npm error could not determine executable to run
npm error A complete log of this run can be found in: C:\Users\User\AppData\Local\npm-cache\_logs\2024-07-25T11_30_21_907Z-debug-0.log
// 2024-07-25T11_30_21_907Z-debug-0.log
0 verbose cli C:\Program Files\nodejs\node.exe C:\Users\User\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js
1 info using [email protected]
2 info using [email protected]
3 silly config load:file:C:\Users\User\AppData\Roaming\npm\node_modules\npm\npmrc
4 silly config load:file:C:\Users\User\Documents\_G\Source code\ATBA\wasm_example_2\.npmrc
5 silly config load:file:C:\Users\User\.npmrc
6 silly config load:file:C:\Users\User\AppData\Roaming\npm\etc\npmrc
7 verbose title npm init wasm-app www
8 verbose argv "init" "wasm-app" "www"
9 verbose logfile logs-max:10 dir:C:\Users\User\AppData\Local\npm-cache\_logs\2024-07-25T11_15_43_784Z-
10 verbose logfile C:\Users\User\AppData\Local\npm-cache\_logs\2024-07-25T11_15_43_784Z-debug-0.log
11 silly logfile start cleaning logs, removing 1 files
12 silly logfile done cleaning log files
13 silly packumentCache heap:4345298944 maxSize:1086324736 maxEntrySize:543162368
14 verbose shrinkwrap failed to load node_modules/.package-lock.json missing from node_modules: ../../../../../../../../usr/local/lib/node_modules/create-wasm-app
15 http fetch GET 200 https://registry.npmjs.org/create-wasm-app 311ms (cache revalidated)
16 verbose stack Error: could not determine executable to run
16 verbose stack     at getBinFromManifest (C:\Users\User\AppData\Roaming\npm\node_modules\npm\node_modules\libnpmexec\lib\get-bin-from-manifest.js:17:23)
16 verbose stack     at exec (C:\Users\User\AppData\Roaming\npm\node_modules\npm\node_modules\libnpmexec\lib\index.js:202:15)
16 verbose stack     at async Init.execCreate (C:\Users\User\AppData\Roaming\npm\node_modules\npm\lib\commands\init.js:136:5)
16 verbose stack     at async Init.exec (C:\Users\User\AppData\Roaming\npm\node_modules\npm\lib\commands\init.js:44:14)
16 verbose stack     at async Npm.exec (C:\Users\User\AppData\Roaming\npm\node_modules\npm\lib\npm.js:207:9)
16 verbose stack     at async module.exports (C:\Users\User\AppData\Roaming\npm\node_modules\npm\lib\cli\entry.js:74:5)
17 verbose pkgid [email protected]
18 error could not determine executable to run
19 verbose cwd C:\Users\User\Documents\_G\Source code\ATBA\wasm_example_2
20 verbose os Windows_NT 10.0.22631
21 verbose node v20.16.0
22 verbose npm  v10.8.2
23 verbose exit 1
24 verbose code 1
25 error A complete log of this run can be found in: C:\Users\User\AppData\Local\npm-cache\_logs\2024-07-25T11_15_43_784Z-debug-0.log

Steps to Reproduce

This tutorial.

Expected Behavior

npm init wasm-app www creates www folder.

Actual Behavior

npm init wasm-app www fails.

mkdirp

If the optional folder is more than one level deep, mkdirSync will fail. I know this is true for some node versions at least, but I have not checked the latest if the API changed (I doubt it).
One solution is use package mkdirp, another is manually splitting path string and creating a folder for each.

live reload/automatic recompile for wasm lib?

Summary

The tutorial at https://rustwasm.github.io/docs/book/game-of-life/implementing.html constantly mentions to just wasm-pack build and refresh the webpage, but does not say anything about restarting the npm run start command after each build. Just building doesn't seem to trigger a node recompile to get the updated library into the webpage. I have to restart the node server to get it to load the new version. How can I enable the server to monitor the wasm lib too, or even the .rs files, and automatically rebuild if it detects a change?

Set up CI for this template

CI should

  • run the local version of the template (not 100% sure how to do this with npm init and local packages)
  • verify that it builds afterwards (npm install && ./node_modules/.bin/webpack)

am I missing anything else it should do?

WebAssembly module is included in initial chunk

Describe the Bug

I have followed the example https://rustwasm.github.io/docs/book/game-of-life/implementing.htm and modified it to use the petgraph crate and try to build a module to use wasm to store tree structure for JS.

The module compiles and seems to work following the tutorial, however if I tried to include the package locally in another project e.g. https://github.com/bbofrk/trying-wasm, or even tried publishing the package on npm (https://www.npmjs.com/package/wasm-tree-structure) then installing in into another project. I am getting the same error

WebAssembly module is included in initial chunk. friendly-errors 09:45:56
This is not allowed, because WebAssembly download and compilation must happen asynchronous.

Steps to Reproduce

  1. clone https://github.com/bbofrk/trying-wasm
  2. run npm install
  3. run npm run dev
  4. See error

Expected Behavior

Should not see compile error

Actual Behavior

WebAssembly module is included in initial chunk. friendly-errors 09:45:56
This is not allowed, because WebAssembly download and compilation must happen asynchronous.

Additional Context

This might have something to do with my webpack.config.js or in this case nust.config.js but I could not tell what should be included. So apologis in advance if its my personal error

Electron bundle

I have a bundle like this that is not electron-ready apparently:

const path = require('path').join(__dirname, 'my_project_bg.wasm');
const bytes = require('fs').readFileSync(path);
let imports = {};
imports['./my_project'] = require('./my_project');

const wasmModule = new WebAssembly.Module(bytes);
const wasmInstance = new WebAssembly.Instance(wasmModule, imports);
module.exports = wasmInstance.exports;

Trying to run it in Electron I get this error:

WebAssembly.Compile is disallowed on the main thread, if the buffer size is larger than 4KB. Use WebAssembly.compile, or compile on a worker thread.

Do someone used an app created with create-wasm-app in electron?

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.