@codebucket/vite-sourcemap-patch
v5.0.0
Published
Generic Vite plugin to patch JS code in node_modules at transform time
Downloads
484
Maintainers
Readme
@codebucket/vite-module-patch
Generic Vite plugin to patch JS code (typically in node_modules) at transform time.
Install
npm install -D @codebucket/vite-module-patchUsage
// vite.config.ts
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import { modulePatchPlugin, type ReplaceRule } from "@codebucket/vite-module-patch";
const NEW_PUBLIC_KEY =
"MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAETmFmAX76TSX7OCAZryYH6ahx9VDoXe6pHLrwkCOKocJGgzGe\n" +
"X6UasLVBecNqUdXvDCsLMO8CXrEGfzl5e0QKfS125Y8a9CxjsBTmdO1/Xn/UolQ9n/1nLmD9wnJ/FmqN";
const oldKeyRegex =
/`MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEJDKWHzXT9YZw7WDJy4wr\/VMXBf\+\/afNB[\s\S]*?y1l39NGbMLIoPVzPY6GXTNzQpxRbGn99`/;
const rules: ReplaceRule[] = [
{
test: (id) =>
id.includes("@react-form-builder/designer") && id.endsWith(".js"),
search: oldKeyRegex,
replace: () => "`" + NEW_PUBLIC_KEY + "`",
},
];
export default defineConfig({
plugins: [
react(),
modulePatchPlugin({ rules }),
],
});You can define any number of rules and target any dependency/module path by adjusting the test predicate.
