This makes debugging a lot easier as by default vite instantiates plugins multiple times for each environment.
36 lines
685 B
TypeScript
36 lines
685 B
TypeScript
import type { Plugin } from "vite";
|
|
import * as path from "@std/path";
|
|
|
|
const SHIMS: Record<string, string> = {
|
|
"object.entries": path.join(
|
|
import.meta.dirname!,
|
|
"shims",
|
|
"object.entries",
|
|
"index.ts",
|
|
),
|
|
"supports-color": path.join(
|
|
import.meta.dirname!,
|
|
"shims",
|
|
"supports-color",
|
|
"index.ts",
|
|
),
|
|
};
|
|
|
|
export function shims(): Plugin {
|
|
return {
|
|
name: "fresh:shims",
|
|
sharedDuringBuild: true,
|
|
resolveId: {
|
|
filter: {
|
|
id: /(object\.entries|supports-color)/,
|
|
},
|
|
handler(id) {
|
|
const resolved = SHIMS[id];
|
|
if (resolved !== undefined) {
|
|
return resolved;
|
|
}
|
|
},
|
|
},
|
|
};
|
|
}
|