CRA Webpack依赖关系优化 [英] CRA Webpack Dependency Optimization
问题描述
Create-React-App(或Create-React-App使用的Webpack)在任何阶段(开发,登台或生产)是否都优化了node_modules?也就是说,如果我有这样的导入:
Does Create-React-App (or Webpack used by Create-React-App) at any stage (development, staging or production) optimise your node_modules? That is, if I had an import like this:
从 lodash导入_
,并且仅在我的项目中使用 map
函数。我的用于生产的构建包会包含lodash的全部内容,还是会去除所有其他功能并保留我的代码中引用的那些功能?
and only use the map
function in my project. Would my build bundle for production have all of lodash or would it strip out all other functions and keep the ones that are being referenced in my code?
推荐答案
CRA在
CRA use UglifyJsPlugin
in the webpack.config.prod.js which supports dead code removal.
但是您只应导入所需的功能即可: https:/ /webpack.js.org/guides/tree-shaking/
But you should only import what you need for this to work: https://webpack.js.org/guides/tree-shaking/
这篇关于CRA Webpack依赖关系优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!