When it comes to managing repository size (assuming you're using git):
git rm -r --cached ./node_modules
- Add
/node_modules
to your .gitignore
file
git add .
git commit -m "Remove node_modules from repository"
Concerning build size:
create-react-app
utilizes tree shaking, which helps minimize build size. Some packages offer more modular ways of importing, mentioned in their documentation. For instance, Material UI icons provides two import
options:
// option 1
import AccessAlarmIcon from '@material-ui/icons/AccessAlarm'
import ThreeDRotation from '@material-ui/icons/ThreeDRotation'
// option 2
import { AccessAlarm, ThreeDRotation } from '@material-ui/icons'
Typically, option 1 results in a smaller bundle size.
Regarding size on your development machine:
A significant improvement can be made by switching to a tool like pnpm, which centralizes node_modules
on your local machine and links to them from your project. This avoids redundant module instances.
For overall project cleanliness:
Consider utilizing a tool like depcheck to identify unused dependencies. However, this may be excessive unless it's a specific issue for your project.