You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Feature request: support package.json conditional exports #27904
The thing is, since this output relies on checking globalThis, it is difficult to treeshake in bundlers. It also ships a little bit of unnecessary code for users.
The problem is there seems to be no easy to way to output multiple variants of JS glue code, but only one WebAssembly binary. For example, the wasm-vips library handles this through a custom build script that builds it for both Node and the browser before collapsing the WebAssembly binary into one file. This can be very time consuming, especially if LTO is enabled.
Sadly you correct, there is no easy way to generate different flavors of the JS glue code around a common wasm binary. One reason for this is the the JS and Wasm code, in the general case, can have dependencies on both directions. A build that runs on node, for example, might have JS code that depends on native Wasm exports that the Web build does not depend on (thus the Wasm binary differs between them).
We do have --post-link argument to emcc which is kind of designed to do this, but its has limited usage/testing. If you have an already-linked Wasm binary that you know/think should be universal you could run emcc --post-link foo.wasm -sENVIRONMENTS=node and then emcc --post-link foo.wasm -sENVIRONMENTS=web to create two different flavors of the glue code.
Activity
sbc100 commentedon Oct 7, 2026
Sadly you correct, there is no easy way to generate different flavors of the JS glue code around a common wasm binary. One reason for this is the the JS and Wasm code, in the general case, can have dependencies on both directions. A build that runs on node, for example, might have JS code that depends on native Wasm exports that the Web build does not depend on (thus the Wasm binary differs between them).
We do have
--post-linkargument toemccwhich is kind of designed to do this, but its has limited usage/testing. If you have an already-linked Wasm binary that you know/think should be universal you could runemcc --post-link foo.wasm -sENVIRONMENTS=nodeand thenemcc --post-link foo.wasm -sENVIRONMENTS=webto create two different flavors of the glue code.