fresh icon indicating copy to clipboard operation
fresh copied to clipboard

docs: add plugin example

Open marvinhagemeister opened this issue 1 year ago • 2 comments

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],
});

marvinhagemeister avatar Jan 07 '24 21:01 marvinhagemeister

Is this different than #1555?

deer avatar Jan 08 '24 09:01 deer

Probably not really. They look closely related.

marvinhagemeister avatar Jan 08 '24 09:01 marvinhagemeister