js
import pkg from "./package.json";
pkg.name; // => "my-package"
.jsoncJSON with comments. Files are parsed and inlined into the bundle as a JavaScript object.
js
import config from "./config.jsonc";
config.name; // => "my-config"
.tomlTOML files are parsed and inlined into the bundle as a JavaScript object.
js
import config from "./bunfig.toml";
config.logLevel; // => "debug"
.yaml .ymlYAML files are parsed and inlined into the bundle as a JavaScript object.
js
import config from "./config.yaml";
config.name; // => "my-app"
.txtThe contents of the text file are read and inlined into the bundle as a string.
js
import contents from "./file.txt";
console.log(contents); // => "Hello, world!"
.htmlHTML files are processed and any referenced assets (scripts, stylesheets, images) are bundled..cssCSS files are bundled together into a single .css file in the output directory..node .wasmThese files are supported by the Bun runtime, but during bundling they are treated as assets. Assets If the bundler encounters an import with an unrecognized extension, it treats the imported file as an external file. The referenced file is copied as-is into outdir, and the import is resolved as a path to the file. InputOutputCopy// bundle entrypoint import logo from "./logo.svg"; console.log(logo); The exact behavior of the file loader is also impacted by naming and publicPath. Refer to the Bundler > Loaders page for more complete documentation on the file loader. Plugins The behavior described in this table can be overridden or extended with plugins. Refer to the Bundler > Loaders page for complete documentation. API entrypoints Required An array of paths corresponding to the entrypoints of our application. One bundle will be generated for each entrypoint. JavaScript CLIbuild.tsCopyconst result = await Bun.build({ entrypoints: ["./index.ts"], }); // => { success: boolean, outputs: BuildArtifact[], logs: BuildMessage[] } terminalCopybun build ./index.ts files A map of file paths to their contents for in-memory bundling. This allows you to bundle virtual files that don’t exist on disk, or override the contents of files that do exist. This option is only available in the JavaScript API. File contents can be provided as a string, Blob, TypedArray, or ArrayBuffer. Bundle entirely from memory You can bundle code without any files on disk by providing all sources via files: build.tsCopyconst result = await Bun.build({ entrypoints: ["/app/index.ts"], files: { "/app/index.ts": ` import { greet } from "./greet.ts"; console.log(greet("World")); `, "/app/greet.ts": ` export function greet(name: string) { return "Hello, " + name + "!"; } `, }, }); const output = await result.outputs[0].text(); console.log(output); When all entrypoints are in the files map, the current working directory is used as the root. Override files on disk In-memory files take priority over files on disk. This lets you override specific files while keeping the rest of your codebase unchanged: build.tsCopy// Assume ./src/config.ts exists on disk with development settings await Bun.build({ entrypoints: ["./src/index.ts"], files: { // Override config.ts with production values "./src/config.ts": ` export const API_URL = "https://api.production.com"; export const DEBUG = false; `, }, outdir: "./dist", }); Mix disk and virtual files Real files on disk can import virtual files, and virtual files can import real files: build.tsCopy// ./src/index.ts exists on disk and imports "./generated.ts" await Bun.build({ entrypoints: ["./src/index.ts"], files: { // Provide a virtual file that index.ts imports "./src/generated.ts": ` export const BUILD_ID = "${crypto.randomUUID()}"; export const BUILD_TIME = ${Date.now()}; `, }, outdir: "./dist", }); This is useful for code generation, injecting build-time constants, or testing with mock modules. outdir The directory where output files will be written. JavaScript CLIbuild.tsCopyconst result = await Bun.build({ entrypoints: ['./index.ts'], outdir: './out' }); // => { success: boolean, outputs: BuildArtifact[], logs: BuildMessage[] } terminalCopybun build ./index.ts --outdir ./out If outdir is not passed to the JavaScript API, bundled code will not be written to disk. Bundled files are returned in an array of BuildArtifact objects. These objects are Blobs with extra properties; see Outputs for complete documentation. build.tsCopyconst result = await Bun.build({ entrypoints: ["./index.ts"], }); for (const res of result.outputs) { // Can be consumed as blobs await res.text(); // Bun will set Content-Type and Etag headers new Response(res); // Can be written manually, but you should use `outdir` in this case. Bun.write(path.join("out", res.path), res); } When outdir is set, the path property on a BuildArtifact will be the absolute path to where it was written to. target The intended execution environment for the bundle. JavaScript CLIbuild.tsCopyawait Bun.build({ entrypoints: ['./index.ts'], outdir: './out', target: 'browser', // default }) terminalCopybun build ./index.ts --outdir ./out --target browser Depending on the target, Bun will apply different module resolution rules and optimizations. browserDefault. For generating bundles that are intended for execution by a browser. Prioritizes the "browser" export condition when resolving imports. Importing any built-in modules, like node:events or node:path will work, but calling some functions, like fs.readFile will not work. bunFor generating bundles that are intended to be run by the Bun runtime. In many cases, it isn’t necessary to bundle server-side code; you can directly execute the source code without modification. However, bundling your server code can reduce startup times and improve running performance. This is the target to use for building full-stack applications with build-time HTML imports, where both server and client code are bundled together.All bundles generated with target: "bun" are marked with a special // @bun pragma, which indicates to the Bun runtime that there’s no need to re-transpile the file before execution.If any entrypoints contains a Bun shebang (#!/usr/bin/env bun) the bundler will default to target: "bun" instead of "browser".When using target: "bun" and format: "cjs" together, the // @bun @bun-cjs pragma is added and the CommonJS wrapper function is not compatible with Node.js. nodeFor generating bundles that are intended to be run by Node.js. Prioritizes the "node" export condition when resolving imports, and outputs .mjs. In the future, this will automatically polyfill the Bun global and other built-in bun:* modules, though this is not yet implemented. format Specifies the module format to be used in the generated bundles. Bun defaults to "esm", and provides experimental support for "cjs" and "iife". format: “esm” - ES Module This is the default format, which supports ES Module syntax including top-level await, import.meta, and more. JavaScript CLIbuild.tsCopyawait Bun.build({ entrypoints: ['./index.tsx'], outdir: './out', format: "esm", }) terminalCopybun build ./index.tsx --outdir ./out --format esm To use ES Module syntax in browsers, set format to "esm" and make sure your
智能索引记录
-
2026-02-27 23:51:44
新闻资讯
成功
标题:枣庄“新春第一会”:护航企业发展 强工兴产谋转型 李锦 枣庄市 民营经济_手机网易网
简介:中经记者陈家运枣庄报道2月25日,枣庄市召开2026年“新春第一会”,主题聚焦“服务企业年”动员部署。会议围绕“强工兴产
-
2026-02-27 19:47:15
综合导航
成功
标题:Pre- & Post-Show Direct Mail PIP - PIP Merritt Island, FL
简介:Let PIP
-
2026-02-27 23:43:49
综合导航
成功
标题:Winnetou hat jetzt auch die Lizenz fürs Green ... [Archiv] - BW7 Forum
简介:Hi in die Runde, die Sache um das Messalina wird jetzt
-
2026-02-27 20:35:41
综合导航
成功
标题:Odaily interviews Arthur Hayes: There is no counterfeit season, I bought a lot of gold barsRecommended Articles Bee Network
简介:Author: Hao Fangzhou Meet Arthur Hayes in person! The cr
-
2026-02-28 05:53:01
综合导航
成功
标题:Fast Casual recent news Nation’s Restaurant News
简介:Explore the latest news and expert commentary on Fast Casual
-
2026-02-28 07:33:17
综合导航
成功
标题:Homepage - Bango
简介:Bango powers the global subscriptions economy with its Digit
-
2026-02-28 10:51:15
法律咨询
成功
标题:预约咨询-阿里云
简介:阿里云预约咨询为企业和开发者提供先进的公共云服务,为用户提供云产品和解决方案等在线报价咨询预约流程等信息
-
2026-02-27 17:50:01
视频影音
成功
标题:重生后亲爹把她宠上天第24集红豆剧场_在线播放[高清流畅]_爽文短剧
简介:爽文短剧_重生后亲爹把她宠上天剧情介绍:重生后亲爹把她宠上天是由内详执导,内详等人主演的,于2025年上映,该重生讲述的
-
2026-02-27 16:42:37
法律咨询
成功
标题:想做非诉律师?学校牌子比法学知识重要 - 律师路上 - 学法网 - 学法网 xuefa.com 与法律人共成长!
简介:我眼中的非诉律师:初探非诉律师的职业发展 ,学法网
-
2026-02-28 00:00:28
综合导航
成功
标题:人族鎮守使-第七百九十一章 暗淵的拉攏,加入神盟!最新章節-台灣小說網
简介:台灣小說網整理人族鎮守使全集無彈窗在線閱讀,當前章節:第七百九十一章 暗淵的拉攏,加入神盟!
-
2026-02-27 20:28:35
综合导航
成功
标题:LPN - Skilled Nursing Facility · GQR
简介:Contract - W2 Long term care (LPN/LVN) Licensed Practical/Vo
-
2026-02-28 09:22:17
综合导航
成功
标题:ISG job portal - FAQ
简介:Here you will find frequently asked questions and answers ab
-
2026-02-28 07:33:52
综合导航
成功
标题:need the following parts [Archive] - Toyota MR2 Message Board
简介:mk2 parts ----------------------------------------------
-
2026-02-28 08:11:00
综合导航
成功
标题:Learn English and more in Australia & Canada ILSC
简介:Learn English at ILSC Language Schools or study French or Hi
-
2026-02-27 18:02:05
综合导航
成功
标题:What is Privileged Access Management (PAM)?
简介:Privileged Access Management (PAM) controls admin, superuser
-
2026-02-27 20:54:47
综合导航
成功
标题:Caleb Desnoyers Stats And News
简介:Get all the latest stats, news, videos, and more on Caleb De
-
2026-02-27 13:39:55
游戏娱乐
成功
标题:《星刃》发布新更新补丁 修复照片模式崩溃错误_3DM单机
简介:开发商Shift Up为《星刃》发布了新更新补丁,主要修复了照片模式和《尼尔》联动服装出现的错误,具体更新内容如下· 修
-
2026-02-27 12:51:19
综合导航
成功
标题:Dress Up Game: Princess Doll Free Online Yad
简介:Create magical looks in Dress Up Game: Princess Doll, a char
-
2026-02-27 18:40:49
金融理财
成功
标题:月薪2000怎么投资理财(月薪2千怎样投资理财)_火必 Huobi交易所
简介:本篇文章给大家谈谈月薪2000怎么投资理财,以及月薪2千怎样投资理财对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔
-
2026-02-27 19:28:54
综合导航
成功
标题:Unmatched Full Lifecycle Service and Support Burroughs
简介:Unlock the potential of your payment and transaction automat
-
2026-02-28 08:35:35
综合导航
成功
标题:TheDomains.com - Award winning domain name Industry publication on domain news, gTLD's, registrars and registries.
简介:Award winning domain name Industry publication on domain new
-
2026-02-27 17:28:36
综合导航
成功
标题:Greystone College Canada Payment Methods
简介:Find Greystone College tuition payment options, including fl
-
2026-02-27 15:59:54
综合导航
成功
标题:John A Cairns
简介:John A Cairns
-
2026-02-28 05:56:27
综合导航
成功
标题:女人克夫鼻相特征简析_一世迷命理网
简介:关于面相的解读往往与个人的命运紧密相连。关于女人克夫鼻相的解读,更是备受关注。一、尖形鼻头在相术中被认为是一种克夫的鼻相
-
2026-02-27 13:00:49
综合导航
成功
标题:Economy Matters - PwC Middle East
简介:A blog by the economists behind PwC’s Middle East Economy Wa
-
2026-02-28 07:15:38
综合导航
成功
标题:腺样体切除后遗症 - 云大夫
简介:切除以后腺样体组织是没有任何的后遗症的,因为人体的免疫器官是巨大的系统,腺样体组织是巨大系统里面的一部分,但是它是非常小
-
2026-02-28 08:58:48
综合导航
成功
标题:Semiconductor & System Solutions Infineon Technologies
简介:Infineon Semiconductor & System Solutions - MCUs, sensors, a
-
2026-02-28 06:18:00
综合导航
成功
标题:Партнерский договор-оферта (версия 16.01.2025) Рег.ру
简介:Партнерский договор-оферта (версия 16.01.2025)
-
2026-02-27 18:34:08
综合导航
成功
标题:Contact EnviroPro 360 - PR.com
简介:Contact EnviroPro 360 via this online contact form.
-
2026-02-28 11:13:11
综合导航
成功
标题:DUS Airport
简介:Weit über 100 Flugziele mit einem intenationalen Airline-Mix