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

How to use local esbuild binary in the npm package? #592

Closed
remorses opened this issue Dec 12, 2020 · 3 comments · Fixed by #597
Closed

How to use local esbuild binary in the npm package? #592

remorses opened this issue Dec 12, 2020 · 3 comments · Fixed by #597

Comments

@remorses
Copy link
Contributor

I am trying to debug an error in esbuild golang code but i cannot find an easy way of using my local esbuild binary in the esbuild npm package

Maybe we can add an option binaryPath or use an environment variable ESBUILD_BINAERY_PATH as a solution, what do you think?

@remorses remorses changed the title How to use local version of the esbuild binary for the npm package? How to use local esbuild binary in the npm package? Dec 12, 2020
@evanw
Copy link
Owner

evanw commented Dec 14, 2020

There is already a way to do this because esbuild has to do this during its tests. Look for the function installForTests() and its uses. Long story short if you install the esbuild package with the ESBUILD_BIN_PATH_FOR_TESTS environment variable configured, the install script will use that path instead of downloading the binary executable from the internet.

@prantlf
Copy link

prantlf commented Dec 14, 2020

If you need more than swapping testing esbuild binaries, if you need to step through the Go code in a debugger, you can make your IDE execute and debug a custom esbuild binary using the esbuild sources. It can help if looking for a problem by adding extra logging or other output and building test binaries is getting too long.

For example, you can clone this repository and open its folder in VS Code. Once you install the golang.go extension for VS Code, you will be able to create a launcher for esbuild. You would figure out the command line parameters that the esbuild executable needs to build your project (or a part of it) and use them together with the path to your project as the current directory. For example:

{
  "name": "build myproject",
  "type": "go",
  "request": "launch",
  "mode": "auto",
  "program": "${workspaceFolder}/cmd/esbuild",
  "cwd": "/home/me/sources/myproject",
  "args": [
    "--bundle", "src/entry.js", "--outfile=out/bundle.js"
  ]
}

Then you can place breakpoints to esbuild source files, start a debugging session by hitting F5 and inspect what is happening during the build. Then check out a specific commit and debug again. Then make some changes and debug again, etc.

@remorses
Copy link
Contributor Author

ESBUILD_BIN_PATH_FOR_TESTS must be set during installation, i would like to change the used binary path at runtime, can i open a PR?

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 a pull request may close this issue.

3 participants