Skip to content

目的:

  1. CommonJS 和 UMD 兼容性。将 CommonJSUMD 规范转化为 ES 模块规范,以便浏览器支持。

  2. 性能。将 lodash 这样的具有大量内置模块的包,转化为单个模块。

TIP

笔者实际测试了下,发现无论是开发环境,还是生产环境,vite 对于 import { debounce } from 'lodash' 这样的语法,其实是将整个 lodash 包打成了一个依赖。并没有做 tree shaking

  1. 转化第三方包。譬如浏览器对于 import { debounce } from 'lodash' 是无法解析的。报错:Uncaught TypeError: Failed to resolve module specifier "lodash". Relative references must start with either "/", "./", or "../"