Documentation or tutorial on how to use Bun.Transpiler? #925
-
I'm building a quick little app with Bun to experiment with, and so far I find it impressive. I have experience with SPAs and backend, but almost none with SSR. I'm trying to build an app that works both with and without JavaScript in the browser, and there's some logic handled by a backend. I can run my frontend with What I've done so far is just use Example, using Hono: app.get("/index.ts", async (c) => {
let f = Bun.file("./index.ts");
let data = await Bun.readableStreamToText(f.stream());
let t = new Bun.Transpiler({});
let out = t.transformSync(data, "ts");
c.header("Content-Type", "text/javascript;charset=utf-8");
return c.body(out);
}); But right now I am totally blocked because I cannot deal with imports. If my script contains the following: import Cookies from "js-cookie"; Then the JS output will be the same and the browser won't be able to deal with that. When I use import Cookies from "http://localhost:3000/node_modules/js-cookie/dist/js.cookie.mjs"; Which is what I would like to be able to produce programmatically from my Hono handler. I read the docs in In other words, what's the best way to manually do what Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
It seems like I'm getting closer to my goal by using
|
Beta Was this translation helpful? Give feedback.
It seems like I'm getting closer to my goal by using
esbuild
directly (which Bun also uses for some cases). From what I read in the Discord server, transforming is supported (usingBun.Transpiler
), but bundling isn't yet, which is what I think I need in order to make the imports.esbuild
can be used withbun run esbuild
, but it lacks some APIs to be imported and use in a script (child_process
and maybe more?).