Skip to content
Discussion options

You must be logged in to vote

If you want to build a binary with the frontend embedded, here’s the usual approach:

  1. Build the frontend first

    • Run the frontend build command (usually npm run build or yarn build inside the web or frontend folder).
    • This generates static assets (HTML, CSS, JS) in a dist or build directory.
  2. Embed those assets into the Go binary

    • Use Go’s built-in go:embed (available since Go 1.16) to include the frontend files directly:
      import "embed"
      
      //go:embed dist/*
      var frontendFS embed.FS
    • Then serve these files via your HTTP server in Go.
  3. Update your build script

    • Make sure your build pipeline runs the frontend build first, then compiles the Go backend:
      cd web && npm run build
      cd .. && go buil…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@webdevpraveen
Comment options

Answer selected by boojack
Comment options

You must be logged in to vote
2 replies
@wancheng
Comment options

@webdevpraveen
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants