Choosing between dependencies and dev dependencies
I understand various types of dependencies when making libraries, but I still can't figure out whether it's worth dividing dependencies into different groups for applications.
Let's say I use Vite, and how do I figure out where to put it? I use it for building and for running the app after it's built in production. So do I actually use it for production? Should I put such builders and runners as Vite in regular dependencies? Also, I use SASS. I know that It's needed for the building stage only. So should it be a development dependency?
This leads me to another question: is building considered part of the production or development stage? Should dependencies required for the build process be placed in development dependencies or regular dependencies?
19 Replies
Vite sorts most that for you anyway, but all of it should be a dev dependency. If you build fails because vite didn't ship something then move it to a dependency. (you will learn what is a "runtime dep" the more you get into using libs)
How you deploy depends on what you're building.
I.e. static/SSR etc. where your deploying too, etc.
Building is for production and or testing locally aka preview.
During development with vite you should be using run dev script
So building is more about development rather than production?
no
npm run build
is for production or testing locally
npm run dev
is for development
or w/e package manager you use pnpm
goatedbut to build the app you anyway need some development dependencies
yes and those are dev dependencies
so you are doing a build with development dependencies installed
dependencies are things needed to be in /node_modules/ for production
Not during build step
Chances are you are not using anything that needs to be a dependacy again keep it all in dev deps
Vite will tell you during build if so. Also if you were using
create vite
or w/e it should be putting stuff where it needs to be
Like what are you using Vite for just Sass?Should I move everything to development dependencies and then attempt to build the app with all the development dependencies installed, and then preview using the start script? I understand that the next steps may depend on the hosting environment. For example, in one scenario, would I move the build to a hosting service and only install production dependencies there? I still need Vite to run the start script, so should it remain in the regular dependencies?
I'm using Vite with Solid Start https://github.com/solidjs/solid-start
GitHub
GitHub - solidjs/solid-start: SolidStart, the Solid app framework
SolidStart, the Solid app framework. Contribute to solidjs/solid-start development by creating an account on GitHub.
So your package.json should look like this yes?
oh sorry like this
ah nvm I can't find a vite example lol
yes but it's more like a "library", not an app
also, compare these examples:
- https://github.com/solidjs/solid-start/blob/main/examples/bare/package.json: everything is in regular dependencies
- https://github.com/solidjs/solid-start/blob/main/examples/with-vitest/package.json everything is in dev dependencies
GitHub
solid-start/examples/with-vitest/package.json at main · solidjs/sol...
SolidStart, the Solid app framework. Contribute to solidjs/solid-start development by creating an account on GitHub.
yea exactly xD
they are using
vinxi
, it's vite
+ nitro
yea I see that now interesting
but yes it all should be in dev deps 😄
like i've been saying
There are very few things you will need peer deps/deps for. When you know you will know
typically
okay, got it
however, this still remains unclear for me:
I still need Vite to run the start script, so should it remain in the regular dependencies?
no
all of it should be in dev deps
vite especially
maybe I don't understand very well why start script is needed? is it needed only for testing and preview? after moving the build to the hosting service, do I need to run the application using just node and the resulting build?
Vite is only for development/building after its build it shouldn't be shipped
depends on the hosting?
but yes you would just run node if you are using SSR using like entrypoint index.js (what ever its named in start)
CMD ["node", "./build/index.js"]
I'm running in docker but you get the idea
All thier docs mainly show how to deploy to the typical serverless paas companies xD
can't help ya there 😄ohhh, thank you very much!! I got it all now :)