dependencies cho production; devDependencies cho build/test tools (không được bundle vào production) — npm ci trong CI/CD đảm bảo deterministic install từ lock file. npm (Node Package Manager) là công cụ quản lý packages mặc định đi kèm Node.js, với registry hơn 2 triệu packages.
- Phân biệt quan trọng:
npm install reactcài vàodependencies— những gì cần thiết để app chạy trên production.npm install --save-dev jest typescript eslintcài vàodevDependencies— chỉ cần trong quá trình development, không được bundle vào production build.
Ví dụ thực tế: khi deploy lên server, chạy npm install --production sẽ bỏ qua devDependencies, giảm đáng kể dung lượng node_modules.
dependencies for production; devDependencies for build/test tools (not bundled into production) — npm ci in CI/CD ensures deterministic install from the lock file. npm (Node Package Manager) is the default package manager bundled with Node.js, with a registry of over 2 million packages.
- Key distinction:
npm install reactinstalls todependencies— things the app needs to run in production.npm install --save-dev jest typescript eslintinstalls todevDependencies— only needed during development, not bundled into the production build. - Practical example: when deploying to a server, running
npm install --productionskips devDependencies, significantly reducingnode_modulessize. - Common pitfall: installing a production package into devDependencies (app crashes on server) or vice versa (bloated production bundle).
- Besides npm, pnpm (faster, disk-efficient) and Yarn are also widely used.