You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular 7 CLI项目node_modules达660Mb,求优化方案及同行现状问询

Angular 7 node_modules Size: Why It’s Bigger & How to Optimize

Hey there, you’re definitely not alone in noticing this—lots of Angular developers saw a jump in node_modules size when moving from v6 to v7. Let’s walk through why this happens, how to slim it down, and what others are seeing.

Why the Size Jump from Angular 6 to 7?

The main culprits behind the doubled size are:

  • Toolchain Overhaul: Angular 7 introduced a more robust build system with @angular-devkit/build-angular (which replaces older CLI build tools). This package brings in additional dependencies for better build optimization, but adds to the overall size.
  • Updated Dependencies: RxJS 6.x (required in Angular 7) has a different dependency structure than the version used in v6, and TypeScript 3.x (also a requirement) includes more files and sub-dependencies compared to TypeScript 2.x in v6.
  • Expanded Dev Dependencies: Default Angular 7 projects include more comprehensive testing and linting tools (like updated Karma, Jasmine, and Codelyzer versions) that add to the dev dependency footprint.

How to Optimize Your node_modules Size

Here are practical steps to reduce disk usage:

  • Switch to pnpm: This package manager uses hard links and shared dependency stores, so it can cut your node_modules size by 60-70% (down to ~200MB for a default Angular 7 project). Install it with npm install -g pnpm, then run pnpm install instead of npm install.
  • Use npm ci Instead of npm install: npm ci installs dependencies strictly from your package-lock.json, avoiding unnecessary duplicate packages that can creep in with regular npm install. It’s also faster!
  • Clean Up Unused Dev Dependencies: If you don’t need certain tools:
    • Remove e2e testing tools: Uninstall protractor and related packages, then delete the e2e folder.
    • Ditch linting: Remove codelyzer and tslint if you use a different linter or don’t need one.
  • Clear npm Cache: Run npm cache clean --force to delete cached packages, then reinstall with npm install—this can eliminate stale or duplicated cached files.
  • Run npm prune: This command removes any packages that aren’t listed in your package.json (though less likely to help with a fresh project, it’s worth a shot).

What Other Developers Are Seeing

From community discussions, a default Angular 7 project’s node_modules typically ranges from 600-700MB—so your 660MB is totally normal. Angular 6 projects were usually around 300-350MB, so the jump is noticeable but expected due to the tooling upgrades.

One thing to keep in mind: the size of node_modules doesn’t affect your production build output. Angular’s tree-shaking and optimization will strip out unused code, leaving you with a lean dist folder regardless of how big node_modules is.

内容的提问来源于stack exchange,提问作者plvice

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 08:51:05