[Quiz] Dependencies Vs devDependencies
The difference between Dependencies and devDependencies is simple, many of us already know it, and still most devDependencies sections…
![[Quiz] Dependencies Vs devDependencies](/images/-Quiz--Dependencies-Vs-devDependencies-f42ef9885de4/img-1.png)
[Quiz] Dependencies Vs devDependencies
The difference between Dependencies and devDependencies is simple, many of us already know it, and still most devDependencies sections inside a package.json are empty. 🤷♂
In a CI/CD workflow, this directly affects execution time and consequently infrastructure cost. Additionally, more dependencies lead to bigger bundles and increased security risks.
Quiz
Before explaining the difference let me test your knowledge.
For each of the following packages, decide whether it should be categorized as a **dependency** 🌐 (needed for running the application in production) or a **devDependency** 🔧 (only needed during development).
reacteslintwebpackexpressjestaxiostypescriptlodashvitebabelvueprettier
Answers available at the end of this article.
Picking the Right Category
To decide whether a package should be a dependencyor devDependency we need to understand its role in the application.
Dependencies are needed to run the application in production.
Some examples include:
- Frameworks and libraries, like React, Vue, Angular, or Express.
- Utility libraries that your code depends on, such as Lodash or Moment.js.
- Database drivers if your application interacts directly with databases.
DevDependencies are needed during the development phase, but not when running the application in production.
They typically include:
- Code linting tools, like ESLint or TSLint.
- Testing frameworks and libraries, such as Cypress, Jest, Mocha, or Chai.
- Build tools and task runners, like Webpack or Vite.
- Transpilers like Babel or TypeScript, if the compiled code is what runs in production.
- Documentation generation tools.
So the general rule is, that if your application code is not importing a file it should not be in your dependencies.
DevDependencies are installed using the -D flag in all of the popular package managers.
\# npm
npm install -D eslint
\# yarn
yarn add -D eslint
\# pnpm
pnpm add -D eslint
Quiz Answer
react- 🌐 Dependency 🌐eslint- 🔧 DevDependency 🔧webpack- 🔧 DevDependency 🔧express- 🌐 Dependency 🌐jest- 🔧 DevDependency 🔧axios- 🌐 Dependency 🌐typescript- 🔧 DevDependency 🔧lodash- 🌐 Dependency 🌐vite- 🔧 DevDependency 🔧babel- 🔧 DevDependency 🔧vue- 🌐 Dependency 🌐prettier- 🔧 DevDependency 🔧
Did you get them all correct?
If not, your homework is to update your package.json first thing in the morning. 🌞
![Better Vue Components with TypeScript [12 examples]](/_astro/img-1.D1-fPpiS_ZnBJgo.webp)
