Tree Shaking 为什么没把第三方库的无用代码去掉?
我用 Vite + Vue3 开发,引入了 lodash-es,但打包后发现整个库都被打进去了,明明只用了 debounce 啊?
我已经按文档写了 import { debounce } from ‘lodash-es’,也确认 vite.config.js 里没关掉 tree shaking,但 bundle 分析显示 lodash-es 全量引入。是不是我哪里配置错了?
<script setup>
import { debounce } from 'lodash-es'
const handleInput = debounce(() => {
console.log('input changed')
}, 300)
</script>
<template>
<input @input="handleInput" />
</template>
import debounce from 'lodash-es/debounce',用路径引入具体模块就行了。要么在 vite.config.js 加这个: