'How to exclude a package while compiling WebAssembly
I am trying to compile some small Go application to WebAssembly using this command:
GOOS=js GOARCH=wasm go build .
My small app uses some function from 3rd party package that has dependency to golang.org/x/sys/unix that is not supposed to be complied for Web Assembly.
Even if my application does not use any functions from golang.org/x/sys/unix, I can not compile my code to WASM due to error:
imports golang.org/x/sys/unix: build constraints exclude all Go files in /some_path/vendor/golang.org/x/sys/unix
Are there any workarounds?
I tried to refactor the code to extract the functions that I need to another package without dependency to golang.org/x/sys/unix but it's not the easiest thing in this project.
Solution 1:[1]
Build tags can exclude tagged files from being compiled. Have not tested this specific tag, but something like this should work:
// +build !JS
package <snip>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Nicholas |
