A Vite plugin that provides manual pre-bundling of dependencies, allowing developers to define custom code or aliased modules to replace imported packages during Vite's dependency pre-bundling phase. Version 1.4.3 is the latest stable release. It supports Browser, Node.js, and Electron environments, and offers flexible entry configurations including string code, result descriptions with alias rules, and async functions. Key differentiators: fine-grained control over pre-bundling (unlike automatic pre-bundling), compatibility with CommonJS and ESM, and ability to replace modules with custom implementations (e.g., using global variables or local files).
npm install vite-plugin-optimizerVerified import paths — ran on the pinned version, not inferred.
Shows basic usage: replacing a module (vue) with inline code, and aliasing multiple module IDs (fs and node:fs) to a CommonJS module.
Return an object with `alias` property from the function, or return a string for code.
Add the module id to `optimizeDeps.include` if you want Vite to pre-bundle it anyway.
No action needed unless you relied on the old default path; specify `dir` explicitly if needed.
Always provide a valid `code` or return a consistent `replacement` when using alias.
Change to ES module import: `import optimizer from 'vite-plugin-optimizer'`.
Run `npm i vite-plugin-optimizer -D` and ensure `tsconfig.json` includes `moduleResolution: 'node'` and `esModuleInterop: true`.
Ensure `ResultDescription.alias` includes both `find` (string/RegExp) and `replacement` (string).
No dependency data recorded yet.