@postinumero/vite-plugin-module-proxy
v0.2.1
Published
Override module exports
Downloads
110
Readme
@postinumero/vite-plugin-module-proxy
Override module exports
Usage
// For Node.js versions below 22, install and import the polyfill:
//import "core-js/proposals/promise-with-resolvers";
import moduleProxy from "@postinumero/vite-plugin-module-proxy";
import { defineConfig } from "vite";
export default defineConfig({
plugins: [
moduleProxy({
target: "some-module", // string | string[] | Promise
handler: "./modules/some-module.tsx", // string | Promise
// Optional. Default: `options.target`.
// Set `false` to disable re-exporting.
// Set `true` to disable re-exporting `default` and re-export only `*`.
reExportAllFrom: "some-module", // boolean | string | Promise
}),
],
});
./modules/some-module.jsx
:
// Reference to the original module. If there are subsequent proxies for
// the same module, this is a reference to the subsequent proxy.
import * as original from "some-module";
// Not needed. Named exports are re-exported from the original module or
// a subsequent proxy.
// export * from "some-module";
// Override the default export
export default function Component(props) {
if (props.specialCase) {
return <>Something else</>;
}
return <original.default {...props} />;
}
// Override other exports
export const x = original.x.toUpperCase();