Skip to main content

One post tagged with "bun"

View All Tags

· One min read
Libing Chen

最新的Bun v0.1.11版本,添加了Plugin API的支持, 其中一项功能就是支持自定义资源加载器Loader,这个也是esbuild非常强大的地方。 所以Bun也遵循了esbuild's plugin API规范,样例代码如下:

import { plugin } from "bun";
import { renderToStaticMarkup } from "react-dom/server";

// Their esbuild plugin runs in Bun (without esbuild)
import mdx from "@mdx-js/esbuild";
plugin(mdx());

// Usage
import Foo from "./bar.mdx";
console.log(renderToStaticMarkup(<Foo />));

现在你也可以在Bun中直接到导入http文件,通过一下npm install -D bun-plugin-httpfile添加一下bun-plugin-httpfilepackage,然后样例代码如下:

import { plugin } from "bun";

import httpfilePlugin from 'bun-plugin-httpfile';
plugin(httpfilePlugin());

// Usage
import {myIp} from "./index.http";
let response = await myIp();
console.log(await response.text());

最后项目地址: https://github.com/servicex-sh/bun-plugin-httpfile 欢迎Issue和PR。