Demystifying `devDependencies` and `dependencies`

Michael Scott Hertzberg on August 24, 2018

If you aren't familiar, devDependencies and dependencies are two properties that are added to package.json when a package is installed as a devel... [Read Full]
markdown guide
 

The second paragraph is confusing.
Why should I have Webpack or something that webpack is bundling in dependencies? Both are often (there are exceptions) used only in development. Only server dependencies should be in dependencies?

 

Hi Mihail,

I understand your confusion in the sentence when I say:

You should ensure that these packages are present in dependencies, as they're needed at runtime.

these packages refers to all required dependencies that your application needs at run-time. Not specifically Webpack or Rollup.

 

Yeah, but I mean I put my webpack and clientside dependencies into devDependencies. And it works out great.

Seems more semantic than downloading unused packages. 🤔
The less packages in production, the faster and safer 🤔
Maybe we should just Rollup our servers and not have runtime dependencies at all 🤔

 

Question: if I have code referencing a devDependency. And that code continue to exist on prod, my app would break, correct? Then should I remove my code when deploying?

 

Hi Vic,

If your code references a dependency, it should be in dependencies, otherwise your app will break. You'd generally reserve devDependencies for things like babel plugins and presets, test runners. Things that are needed to compile your application.

 
 

Also one option would be to check envoriment. And when building for production uglify removes unnecessary code. See more in uglify documentation.

I actually use this also for building multible different sites from one source.

code of conduct - report abuse