feat: add vite-plugin-node-polyfills to support Node.js globals in Vite

This commit is contained in:
Peter Wood
2025-04-22 14:12:34 -04:00
parent deb2134b82
commit 40fc872108
5 changed files with 1632 additions and 33 deletions

View File

@@ -1,7 +1,26 @@
import { defineConfig } from "vite";
// Import the new plugin
import { nodePolyfills } from "vite-plugin-node-polyfills";
export default defineConfig({
// Keep build target reasonable, 'modules' is often a good balance
build: {
target: "es2020", // Or try 'es2020' or 'modules' if 'esnext' doesn't work
target: "modules",
// Rollup options are not needed for this plugin
},
plugins: [
// Add the plugin to Vite's plugins array
nodePolyfills({
// Options (optional):
// - 'true'/'false' to include/exclude specific polyfills.
// - 'build' to only include polyfills for the build.
// - 'dev' to only include polyfills for the dev server.
// By default, it polyfills globals like `Buffer` and `process`.
// You might need to explicitly enable others if errors persist.
// Example: globals: { Buffer: true, global: true, process: true },
// Example: protocolImports: true, // If you need imports like 'node:fs'
}),
],
// optimizeDeps and resolve.alias sections related to polyfills
// are likely no longer needed with this plugin.
});