mono-runner
Version:
A script runner for mono repos that just works. Use Mono to run separate compilers and dev servers for your packages at once, build only dependent packages or format everything at once.
38 lines (32 loc) • 833 B
text/typescript
import type { Plugin } from "vite";
import { getWorkspacePackagesSync, rootPath } from "../utils/packages";
import { join } from "path";
type PathMap = {
[key: string]: string;
};
type MonoViteConfig = {
prodRewrite?: PathMap;
devRewrite?: PathMap;
};
export const ViteMonoPlugin: (config: MonoViteConfig) => Plugin = (config) => {
const packages = getWorkspacePackagesSync();
const packageKeys = Object.keys(packages);
return {
name: "mono-vite-plugin",
config: (opts, env) => {
},
resolveId: (id: string) => {
for (let index = 0; index < packageKeys.length; index++) {
const key = packageKeys[index];
if(id.startsWith(key)){
const path = packages[key];
const newPath = id.replace(key, path);
return {
id: join(rootPath, newPath),
}
}
}
return undefined;
}
}
};