CRA Webpack Dependency Optimization

2019-08-24 00:01发布

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:

import _ from '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?

1条回答
孤傲高冷的网名
2楼-- · 2019-08-24 00:26

CRA use UglifyJsPlugin in the webpack.config.prod.js which supports dead code removal.

But you should only import what you need for this to work: https://webpack.js.org/guides/tree-shaking/

查看更多
登录 后发表回答