Created
January 5, 2025 23:09
-
-
Save canadaduane/1386067a79051b76f23064fd863bc25a to your computer and use it in GitHub Desktop.
Bun loader for DLight
This file contains 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: "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