| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- import { transformAsync } from "@babel/core"
- // @ts-expect-error - Types not important.
- import ts from "@babel/preset-typescript"
- // @ts-expect-error - Types not important.
- import solid from "babel-preset-solid"
- import { type BunPlugin } from "bun"
- const solidTransformPlugin: BunPlugin = {
- name: "bun-plugin-solid",
- setup: (build) => {
- build.onLoad({ filter: /\/node_modules\/solid-js\/dist\/server\.js$/ }, async (args) => {
- const path = args.path.replace("server.js", "solid.js")
- const file = Bun.file(path)
- const code = await file.text()
- return { contents: code, loader: "js" }
- })
- build.onLoad({ filter: /\/node_modules\/solid-js\/store\/dist\/server\.js$/ }, async (args) => {
- const path = args.path.replace("server.js", "store.js")
- const file = Bun.file(path)
- const code = await file.text()
- return { contents: code, loader: "js" }
- })
- build.onLoad({ filter: /\.(js|ts)x$/ }, async (args) => {
- const file = Bun.file(args.path)
- const code = await file.text()
- const transforms = await transformAsync(code, {
- filename: args.path,
- presets: [
- [
- solid,
- {
- moduleName: "@opentui/solid",
- generate: "universal",
- },
- ],
- [ts],
- ],
- })
- return {
- contents: transforms?.code ?? "",
- loader: "js",
- }
- })
- },
- }
- export default solidTransformPlugin
|