diff --git a/cmd/tsconnect/common.go b/cmd/tsconnect/common.go index efe35460f..a3941e614 100644 --- a/cmd/tsconnect/common.go +++ b/cmd/tsconnect/common.go @@ -119,6 +119,9 @@ func runYarn(args ...string) error { // from entry points to hashed file names. type EsbuildMetadata struct { Outputs map[string]struct { + Inputs map[string]struct { + BytesInOutput int64 `json:"bytesInOutput"` + } `json:"inputs,omitempty"` EntryPoint string `json:"entryPoint,omitempty"` } `json:"outputs,omitempty"` } diff --git a/cmd/tsconnect/index.html b/cmd/tsconnect/index.html index ba9a530f6..0d78a1cec 100644 --- a/cmd/tsconnect/index.html +++ b/cmd/tsconnect/index.html @@ -3,7 +3,9 @@ + Tailscale Connect +
@@ -38,6 +40,5 @@ enabled. Give it a try!
- diff --git a/cmd/tsconnect/serve.go b/cmd/tsconnect/serve.go index da9878bf5..53100c090 100644 --- a/cmd/tsconnect/serve.go +++ b/cmd/tsconnect/serve.go @@ -83,10 +83,19 @@ func generateServeIndex(distFS fs.FS) ([]byte, error) { return nil, fmt.Errorf("Could not parse esbuild-metadata.json: %w", err) } entryPointsToHashedDistPaths := make(map[string]string) + mainWasmPath := "" for outputPath, output := range esbuildMetadata.Outputs { if output.EntryPoint != "" { entryPointsToHashedDistPaths[output.EntryPoint] = path.Join("dist", outputPath) } + if path.Ext(outputPath) == ".wasm" { + for input := range output.Inputs { + if input == "src/main.wasm" { + mainWasmPath = path.Join("dist", outputPath) + break + } + } + } } indexBytes := rawIndexBytes @@ -96,6 +105,10 @@ func generateServeIndex(distFS fs.FS) ([]byte, error) { indexBytes = bytes.ReplaceAll(indexBytes, []byte(defaultDistPath), []byte(hashedDistPath)) } } + if mainWasmPath != "" { + mainWasmPrefetch := fmt.Sprintf("\n", mainWasmPath) + indexBytes = bytes.ReplaceAll(indexBytes, []byte(""), []byte(mainWasmPrefetch)) + } return indexBytes, nil }