fresh
fresh copied to clipboard
docs: add plugin example
It's easier to understand the API if we have a snippet example in our docs what a plugin looks like. Something like:
const myCoolPlugin = {
name: "my-cool-plugin",
async configResolved(config) {
console.log("read the resolved fresh config")
}
async buildStart() {
console.log("build is starting")
},
async buildEnd() {
console.log("build finished")
};
middlewares: [
{
path: "/",
middleware: {
handler: (req, ctx) => {
console.log(`I'm a plugin middleware on ${req.url}`);
return ctx.next();
}
}
}
]
}
And it can be used like this:
// fresh.config.ts
import { defineConfig } from "$fresh/server.ts";
import myCoolPlugin from "./my-cool-plugin.ts";
export default defineConfig({
plugins: [myCoolPlugin],
});
Is this different than #1555?
Probably not really. They look closely related.