Last active
January 23, 2025 05:58
-
-
Save canadaduane/1386067a79051b76f23064fd863bc25a to your computer and use it in GitHub Desktop.
Bun loader for DLight
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import type { BunPlugin } from "bun"; | |
import { transform } from "@babel/core"; | |
import dlight, { type DLightOption } from "babel-preset-dlight"; | |
export const dlightPlugin = (): BunPlugin => ({ | |
name: "bun-plugin-dlight", | |
setup(build) { | |
build.onLoad({ filter: /\.(view|model)\.[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