bun: 安装与使用

JavaScript 运行时 Bun 快速预览
更新于: 2024-05-10 10:26:23

安装

export的配置已经在 @jswork/ushell-module-nodejs 里添加

# 官方推荐的安装方式
curl -fsSL https://bun.sh/install | bash
# 利用 npm 安装,如果电脑有多版本的 nodejs 就不推荐这种了
npm install --location=global bun
❯ curl https://bun.sh/install | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  5046    0  5046    0     0   5091      0 --:--:-- --:--:-- --:--:--  5086
######################################################################## 100.0%d
bun was installed successfully to /Users/aric.zheng/.bun/bin/bun

Manually add the directory to your $HOME/.bashrc (or similar)

   export BUN_INSTALL="/Users/aric.zheng/.bun"
   export PATH="$BUN_INSTALL/bin:$PATH"

To get started, run

   bun --help

.dotfiles on 🌱 mast

升级

curl -fsSL https://bun.sh/install | bash

建议

现在这个东西还不成熟,可以试验性的玩一下,但不建议用于生产。

开发一个cli

打包下来 56MB,太大了。

const args = process.argv.slice(2);
const id = args[0];
const url = `https://www.ncbi.nlm.nih.gov/sviewer/viewer.fcgi?id=${id}&report=fasta`;
const res = await fetch(url).then((r) => r.text());

console.log(url);
console.log();
console.log(res.trim());
bun build ./cli.ts --compile --outfile mycli

还存在的问题

cheatsheet

这里列举一些有趣,有用的。

用法代码
开发一个 cli 工具
# https://bun.sh/docs/bundler/executables
bun build ./cli.ts --compile --outfile mycli

参考