Performance: Installing packages (dependencies vs devDependencies)
This concept affects the bundle size and load time of your application by controlling which packages are included in production builds.
Jump into concepts and practice - no test required
npm install --save react react-dom
npm install --save-dev react react-dom
| Pattern | Bundle Size Impact | Load Time Impact | Runtime Errors | Verdict |
|---|---|---|---|---|
| Installing runtime packages as devDependencies | Excluded from bundle | Causes runtime errors or missing code | Yes | [X] Bad |
| Installing runtime packages as dependencies | Included in bundle | Loads correctly and fast | No | [OK] Good |
| Installing build/test tools as dependencies | Increases bundle by 100-300kb+ | Slows load and parse time | No | [X] Bad |
| Installing build/test tools as devDependencies | Excluded from production bundle | No impact on load time | No | [OK] Good |
npm install express installs the package as a regular dependency by default.npm install without flags [OK]--save-dev tells npm to install the package as a development dependency.npm install --save-dev jest installs Jest as a devDependency, which is used for testing during development.--save-dev flag [OK]package.json snippet, which package will NOT be installed when running npm install --production?
{
"dependencies": {
"express": "^4.18.2"
},
"devDependencies": {
"mocha": "^10.2.0"
}
}--production flag tells npm to install only the packages listed under dependencies, skipping devDependencies.mocha is under devDependencies, so it will NOT be installed with npm install --production.npm install --save-dev eslint but later realize you need eslint as a regular dependency. What is the best way to fix this?npm install eslint alone will not move it from devDependencies to dependencies if already installed as devDependency.webpack and babel packages. webpack is needed to run your app, but babel is only needed during development. Which commands correctly install them with proper dependency types?npm install webpack for runtime dependency and npm install --save-dev babel for development dependency.