Giter Site home page Giter Site logo

blackaslight / wasm-bundler Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 5 KB

Easily, via the cli, convert wasm binary files into js files to be bundled up together as one single file.

Home Page: https://jsr.io/@doctor/wasm-bundler

License: MIT License

TypeScript 100.00%
browser bundle convert deno embed javascript transpile typescript wasm webassembly

wasm-bundler's Introduction

Wasm Bundler

Wasm Bundler is a simple script that enables one to embed their .wasm file into their javascript code by creating a .js file that has the wasm binary file gzipped and stringified to base64 for load. This file can then, if one desired, be bundled into other code of yours via your desired bundler. The generated code does need the @doctor/encoding-stream/base64 dependency to function properly.

Example 1

Example Command

Assuming there was a static/wasm/app.js and static/wasm/app_bg.wasm file already in your code base.

deno run --allow-read --allow-write @doctor/wasm-bundler static/wasm/app_bg.wasm ./app.js static/wasm/embed.js

Output

import { DecodeBase64Stream } from '@doctor/encoding-stream/base64'
import x from './app.js'

x(new Response(
	ReadableStream.from((async function* () {
		yield 'Imagine Repeated Base64 Strings Here!'
	})())
		.pipeThrough(new DecodeBase64Stream())
		.pipeThrough(new DecompressionStream('gzip'))
))

Example 2

Example Import

Assuming there was a static/wasm/app.js and static/wasm/app_bg.wasm file already in your code base.

import { WasmToJs } from '@doctor/wasm-bundler/mod'

(await Deno.open('./static/wasm/app_bg.wasm'))
	.readable
	.pipeThrough(new WasmToJs('./app.js'))
	.pipeTo(Deno.stdout.writable)

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.