6
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

TypeScriptをシングルバイナリ実行ファイルにする。ついでにMCPサーバーもシングルバイナリー化

6
Posted at

こんなTypeScriptのソースがあるとします。

cli.ts
console.log("Hello world!");

これを実行ファイルに変換します。

Bunを使う場合

bun build ./cli.ts --compile --outfile cli-bun

Windowsの場合はcli-bun.exeが生成されます。

ちなみに、アイコンはbunのものです。圧がすごい

image.png

クロスコンパイルもできます。

# Mac向けバイナリを生成
bun build ./cli.ts --compile --target=bun-darwin-arm64 --outfile cli-bun

Denoを使う場合

deno compile --output cli-deno cli.ts

こちらはWindows標準っぽいアイコンになりました。

image.png

Denoもクロスコンパイルできます。

deno compile --target aarch64-apple-darwin --output cli-deno cli.ts

ファイルサイズを比較

Hello world!を出力するだけですが、Bun版が約100MB、Deno版が約80MBです。

image.png

npxで使用するMCPサーバーをシングルバイナリ化する

最近はリモートMCPが主流ですが、たまにあるnpxでインストールして使う系のMCPサーバーをシングルバイナリにします。Bunで試しました。

お題としてSequential Thinking MCP Serverを取り上げます。

まずbun iで取得します。

bun i @modelcontextprotocol/server-sequential-thinking

node_modules/@modelcontextprotocol/server-sequential-thinking/package.jsonbinを確認するとこうなっています。

  "bin": {
    "mcp-server-sequential-thinking": "dist/index.js"
  },

実態はdist/index.jsということですね。

なので、このファイルを先程のように

bun build ./node_modules/@modelcontextprotocol/server-sequential-thinking/dist/index.js --compile --outfile sequential-thinking

sequential-thinking.exeが生成されます。

非開発者のPCにNodeが入ってなくてもシングルバイナリにして配布が捗りますね!

参考

6
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?