Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable using esbuild with deno and wasm #2359

Merged
merged 3 commits into from
Jun 30, 2022
Merged

enable using esbuild with deno and wasm #2359

merged 3 commits into from
Jun 30, 2022

Conversation

evanw
Copy link
Owner

@evanw evanw commented Jun 30, 2022

The native implementation of esbuild is much faster than the WebAssembly version, but some people don't want to give Deno the --allow-run permission necessary to run esbuild and are ok waiting longer for their builds to finish when using the WebAssembly backend. With this PR, you can now use esbuild via WebAssembly in Deno. To do this you will need to import from wasm.js instead of mod.js:

import * as esbuild from 'https://deno.land/x/esbuild@v0.14.48/wasm.js'
const ts = 'let test: boolean = true'
const result = await esbuild.transform(ts, { loader: 'ts' })
console.log('result:', result)

Make sure you run Deno with --allow-net so esbuild can download the WebAssembly module. Using esbuild like this starts up a worker thread that runs esbuild in parallel (unless you call esbuild.initialize({ worker: false }) to tell esbuild to run on the main thread). If you want to, you can call esbuild.stop() to terminate the worker if you won't be using esbuild anymore and you want to reclaim the memory.

Note that Deno appears to have a bug where background WebAssembly optimization can prevent the process from exiting for many seconds. If you are trying to use Deno and WebAssembly to run esbuild quickly, you may need to manually call Deno.exit(0) after your code has finished running.

Fixes #2323

@evanw evanw merged commit 79a3512 into master Jun 30, 2022
@evanw evanw deleted the deno-wasm branch June 30, 2022 03:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

deno-esbuild: A request for WebAssembly support
1 participant