import type { Plugin } from "esbuild-wasm"; interface ShakespearePluginOptions { esmUrl: string; } /** * Shakespeare plugin for dependency polyfills and workarounds. * This plugin handles specific dependencies that need custom implementations * or dummy APIs to work correctly in the browser environment. */ export function shakespearePlugin(options: ShakespearePluginOptions): Plugin { return { name: "shakespeare", setup(build) { // Handle Tailwind CSS configuration files (v3). // The synthetic entry loads the v3 Play CDN runtime and assigns the // project's tailwind.config.{js,ts} to the global `tailwind.config`. build.onResolve({ filter: /^shakespeare:tailwind\.config\.(js|ts)$/ }, (args) => { return { path: args.path, namespace: "shakespeare-tailwind", }; }); build.onLoad({ filter: /.*/, namespace: "shakespeare-tailwind" }, async (args) => { const { pathname } = new URL(args.path); return { contents: ` import tailwindConfig from "@/../${pathname}"; import "${options.esmUrl}/tailwindcss-cdn@3"; tailwind.config = tailwindConfig; `, loader: "js", }; }); // Handle Tailwind CSS v4 runtime. // v4 has no JS config (theming is done in CSS via `@theme`) and the // `@tailwindcss/browser@4` runtime auto-detects `