Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example of Solid plugin for Vite
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
You can’t perform that action at this time.