Created
July 11, 2020 20:14
-
-
Save ryansolid/dbd57322a8ff50d18aeeae0622fc615c to your computer and use it in GitHub Desktop.
Example of Solid plugin for Vite
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 { join } from "path"; | |
import { Plugin } from "vite"; | |
import { babel } from "@rollup/plugin-babel"; | |
import { transformFileSync } from "@babel/core"; | |
const presets = ["solid", "@babel/preset-typescript"]; | |
export const solidPlugin: Plugin = { | |
rollupInputOptions: { | |
plugins: [ | |
babel({ | |
presets, | |
babelHelpers: "bundled", | |
extensions: [".js", ".ts", ".jsx", ".tsx"], | |
}), | |
], | |
}, | |
configureServer: ({ root, app }) => { | |
app.use(async (ctx, next) => { | |
if (/\.(t|j)s(x)?$/.test(ctx.path) && !ctx.path.includes("@modules")) { | |
const result = transformFileSync(join(root, ctx.path), { | |
presets, | |
sourceMaps: true, | |
}); | |
ctx.type = "js"; | |
ctx.body = result.code; | |
ctx.map = result.map; | |
return; | |
} | |
await next(); | |
}); | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does this work in Vite2?