Skip to content

Instantly share code, notes, and snippets.

@canadaduane
Created January 5, 2025 23:09
Show Gist options
  • Save canadaduane/1386067a79051b76f23064fd863bc25a to your computer and use it in GitHub Desktop.
Save canadaduane/1386067a79051b76f23064fd863bc25a to your computer and use it in GitHub Desktop.
Bun loader for DLight
import type { BunPlugin } from "bun";
import { transform } from "@babel/core";
import dlight, { type DLightOption } from "babel-preset-dlight";
export const dlightPlugin: BunPlugin = {
name: "DLight loader",
setup(build) {
build.onLoad({ filter: /\.view\.[tj]s$/ }, async (args) => {
const options: DLightOption = {};
const code = await Bun.file(args.path).text();
const result = transform(code, {
babelrc: false,
configFile: false,
presets: [[dlight, options]],
sourceMaps: true,
filename: args.path,
});
if (!result || !result.code) {
throw new Error(`Babel failed to process ${args.path}`);
}
return {
contents: result.code,
loader: "js",
};
});
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment