Bun 安装


开发、测试、运行和捆绑 JavaScript 和 TypeScript 项目 - 全部使用 Bun。

1. 什么是 Bun

Bun 是一个从头开始构建的新 JavaScript 运行时,旨在服务现代 JavaScript 生态系统。它有三个主要设计目标:

  • 速度:Bun 启动快,运行也快。它扩展了 JavaScriptCore,即为 Safari 构建的注重性能的 JS 引擎。随着计算向边缘发展,这一点至关重要。
  • 优雅的 API:Bun 提供了一组最小的高度优化的 API,用于执行常见任务,例如启动 HTTP 服务器和写入文件。
  • 凝聚力 DX:Bun 是一个用于构建 JavaScript 应用程序的完整工具包,包括包管理器、测试运行器和捆绑器。

Bun 被设计为 Node.js 的直接替代品。它原生实现了数百个 Node.js 和 Web API,包括 fs 、 path 、 Buffer 等。

Bun 的目标是运行世界上大部分的服务器端 JavaScript,并提供提高性能、降低复杂性并提高开发人员生产力的工具。

2. Bun 官网地址

https://bun.sh/

3. Bun 安装

运行下面命令进行安装,

# 支持在 macOS、Linux 和 WSL 上安装
curl -fsSL https://bun.sh/install | bash
source /root/.bashrc

运行下面命令进行确认,

bun --help

输出日志,

Bun is a fast JavaScript runtime, package manager, bundler, and test runner. (1.0.20 (09d51486))

Usage: bun <command> [...flags] [...args]

Commands:
  run       ./my-script.ts       Execute a file with Bun
            lint                 Run a package.json script
  test                           Run unit tests with Bun
  x         prettier             Execute a package binary (CLI), installing if needed (bunx)
  repl                           Start a REPL session with Bun

  install                        Install dependencies for a package.json (bun i)
  add       next-app             Add a dependency to package.json (bun a)
  remove    react                Remove a dependency from package.json (bun rm)
  update    webpack              Update outdated dependencies
  link      [<package>]          Register or link a local npm package
  unlink                         Unregister a local npm package
  pm <subcommand>                Additional package management utilities

  build     ./a.ts ./b.jsx       Bundle TypeScript & JavaScript into a single file

  init                           Start an empty Bun project from a blank template
  create    lyra                 Create a new project from a template (bun c)
  upgrade                        Upgrade to latest version of Bun.
  <command> --help               Print help text for command.

Flags:
      --watch                    Automatically restart the process on file change
      --hot                      Enable auto reload in the Bun runtime, test runner, or bundler
      --smol                     Use less memory, but run garbage collection more often
  -r, --preload                  Import a module before other modules are loaded
      --inspect                  Activate Bun's debugger
      --inspect-wait             Activate Bun's debugger, wait for a connection before executing
      --inspect-brk              Activate Bun's debugger, set breakpoint on first line of code and wait
      --if-present               Exit without an error if the entrypoint does not exist
      --no-install               Disable auto install in the Bun runtime
      --install                  Configure auto-install behavior. One of "auto" (default, auto-installs when no node_modules), "fallback" (missing packages only), "force" (always).
  -i                             Auto-install dependencies during execution. Equivalent to --install=fallback.
  -e, --eval                     Evaluate argument as a script
      --prefer-offline           Skip staleness checks for packages in the Bun runtime and resolve from disk
      --prefer-latest            Use the latest matching versions of packages in the Bun runtime, always checking npm
  -p, --port                     Set the default port for Bun.serve
  -b, --bun                      Force a script or package to use Bun's runtime instead of Node.js (via symlinking node)      --silent                   Don't print the script command
  -v, --version                  Print version and exit
      --revision                 Print version with revision and exit
      --env-file                 Load environment variables from the specified file(s)
      --cwd                      Absolute path to resolve files & entry points from. This just changes the process' cwd.  -c, --config                   Specify path to Bun config file. Default $cwd/bunfig.toml
  -h, --help                     Display this menu and exit

(more flags in bun install --help, bun test --help, and bun build --help)

Learn more about Bun:            https://bun.sh/docs
Join our Discord community:      https://bun.sh/discord

完结!

相关推荐

  1. Bun 安装

    2023-12-30 03:46:02       98 阅读
  2. [BUG]Windows安装WSL报错

    2023-12-30 03:46:02       49 阅读
  3. node依赖安装bug汇总

    2023-12-30 03:46:02       34 阅读
  4. pip安装tf-gpu=2.4的bug解决方案

    2023-12-30 03:46:02       56 阅读
  5. 【Python BUG】anaconda安装报错Error:Cannot unpack file

    2023-12-30 03:46:02       37 阅读
  6. bug】在 Windows 上安装 SDKMAN! 的完整指南

    2023-12-30 03:46:02       30 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-30 03:46:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-30 03:46:02       100 阅读
  3. 在Django里面运行非项目文件

    2023-12-30 03:46:02       82 阅读
  4. Python语言-面向对象

    2023-12-30 03:46:02       91 阅读

热门阅读

  1. 鸿蒙Harmony(十)动画

    2023-12-30 03:46:02       63 阅读
  2. 编程笔记 html5&css&js 002 一些基本概念

    2023-12-30 03:46:02       49 阅读
  3. 送你一台云电脑

    2023-12-30 03:46:02       57 阅读
  4. 系列十一、解压文件到指定目录

    2023-12-30 03:46:02       44 阅读
  5. 面向对象进阶-继承

    2023-12-30 03:46:02       58 阅读
  6. Linux模块编译

    2023-12-30 03:46:02       65 阅读
  7. C++三剑客之std::variant(一)

    2023-12-30 03:46:02       49 阅读
  8. install mpirun

    2023-12-30 03:46:02       69 阅读
  9. 基于SpringBoot的足球社区管理系统

    2023-12-30 03:46:02       64 阅读