beesbuild
Version:
构建工具链
28 lines (27 loc) • 848 B
JavaScript
import rollupJsonNPlugin from "@rollup/plugin-json";
import { isFunction } from "lodash-unified";
const EXPORT_DEFAULT = "export default ";
function jsonPlugin(option, ctx) {
if ((option != null ? option : false) === false) return [];
if (typeof option === "boolean") {
option = {};
}
const plugin = rollupJsonNPlugin(option);
const transform = plugin == null ? void 0 : plugin.transform;
return {
...plugin,
name: "beesbuild:json",
async transform(code, id) {
if (isFunction(transform)) {
const res = await transform.call(this, code, id);
if (res && typeof res !== "string" && "code" in res && res.code && res.code.startsWith(EXPORT_DEFAULT)) {
res.code = res.code.replace(EXPORT_DEFAULT, "module.exports = ");
}
return res;
}
}
};
}
export {
jsonPlugin
};