Replacing the import of lodash with lodash-es is more beneficial to tree-shaking
npm install vite-plugin-replace-lodashEnglish | 中文
A Vite plugin is used to replace lodash with lodash-es to prevent all lodash modules are imported and the bundle volume is too large because it cannot tree-shaking.
Notice: The lodash-es module needs to be installed separately.
npm:
``bash`
npm install vite-plugin-replace-lodash -D
pnpm:
`bash`
pnpm add vite-plugin-replace-lodash -D
`typescript
import { defineConfig } from 'vite';
import { replaceLodash } from 'vite-plugin-replace-lodash';
export default defineConfig({
plugins: [replaceLodash()],
})
``