Files

16 lines
503 B
TypeScript

import type { Plugin } from "vite";
export function daikonCommonJS(): Plugin {
return {
name: "daikon-commonjs",
enforce: "pre",
transform(code, id) {
if (!/\/daikon\/(src|lib)\/.*\.js$/.test(id.replaceAll("\\", "/")))
return;
// Daikon guards static CommonJS imports with a runtime require check.
// Bundlers replace the calls, but leave the check false in browsers.
return code.replace(/typeof require\s*!==\s*['"]undefined['"]/g, "true");
},
};
}