Open niklasgrewe opened 10 months ago
I'm no expert, just happen to be wanting to do the same thing.
https://bun.sh/docs/api/transpiler
This works for me
import { plugin, Transpiler } from "bun";
plugin({
name: "Test",
async setup(build) {
const { readFileSync } = await import("fs");
const transpiler = new Transpiler({ loader: "ts" });
build.onLoad({ filter: /\.(ts)$/ }, (args) => {
let typescript = readFileSync(args.path, "utf8");
const javascript = transpiler.transformSync(typescript);
return {
contents: javascript
};
});
},
});
I noticed a temperamental regression here too. I was using loader: 'tsx'
in a plugin. It used to work. But now it would like work once, and then stop working.
https://bun.sh/docs/runtime/plugins#loaders
Note that the returned object has a loader property. This tells Bun which of its internal loaders should be used to handle the result.
This seems to be broken.
I see the same issue; our Civet plugin doesn't handle JSX with loader: 'tsx'
. Running the Transpiler
manually seems like a reasonable workaround, but I think you also need to give it the tsconfig
manually, which is annoying (in a plugin context, where should we search for it?). I also can't seem to get it to emit the implicit import
for JSX content; see https://github.com/oven-sh/bun/discussions/8335#discussioncomment-9839937
Update: loader: 'tsx'
does seem to work for TypeScript code, whereas loader: 'js'
errors. But loader: 'tsx'
does not support JSX notation.
What version of Bun is running?
0.8.1+16b4bf341acc0f4804f0b6bdf5298c180cd00366
What platform is your computer?
Darwin 22.6.0 arm64 arm
What steps can reproduce the bug?
create a minimal loader that returns static typescript:
using it with the following script
What is the expected behavior?
expected output:
What do you see instead?
get the following error:
Additional information
No response