Vite plugin that resolves edge cases when using RequireJS/AMD in the browser by injecting `var define = false;` into UMD modules, preventing RequireJS from hijacking them. This addresses a specific issue where Vite's UMD-to-CommonJS conversion breaks in a browser RequireJS environment (vitejs/vite#5900). Current version 0.1.4, ships TypeScript types, requires Vite as peer dependency. Use this when you need to serve UMD modules via Vite but the page also includes RequireJS (e.g., legacy dependencies). The plugin is lightweight and scoped to this single concern.
npm install vite-plugin-treat-umd-as-commonjsVerified import paths — ran on the pinned version, not inferred.
Shows how to import and configure the plugin in a Vite config with include/exclude options.
Use `exclude` option to skip modules that should keep their AMD define.
Set `include` option to the file patterns that need treatment.
Use `include` instead of `indluce`.
Check compatibility with your Vite version; ensure tests pass.
Ensure you are not including/excluding the entry module itself. Use more specific patterns.
Load RequireJS before your bundle or exclude the module from treatment.
Run `npm install vite-plugin-treat-umd-as-commonjs` and ensure you are using the named import `{ treatAsCommonjs }`.