Deployment question regarding running `npm run prod` on deploy.
I use Envoy to deploy to a Digital Ocean server and was thinking it would be nice if npm run prod would automatically fire during deployment.
I tried running this directly on the server but the server is missing cross-env, probably laravel-mix, etc npm packages...
I'm considering moving those to regular dependencies instead of dev dependencies... is there any harm in that? Does that sound like a bad idea? Totally standard and go for it?
Curious what the consensus is out there.
I use envoyer.io to deploy projects with zero downtime. One of the steps is npm ci. All compiled assets are excluded from git and everything is built on deployment for production and CI with npm run prod.
So first I do npm ci then it is followed by npm run prod.
Let me try to answer in chunks so maybe my logic will make more sense.
I use Envoy to deploy to a Digital Ocean server and was thinking it would be nice if npm run prod would automatically fire during deployment.
envoyer.io does this so I do not have anything else to recommend. It can be done also on Laravel Forge but zero downtime is quite to my liking.
I tried running this directly on the server but the server is missing cross-env, probably laravel-mix, etc npm packages... I'm considering moving those to regular dependencies instead of dev dependencies... is there any harm in that? Does that sound like a bad idea? Totally standard and go for it?
For me cross-env is in devDependencies and I never had this issue. But the reason I've mentioned npm ci is that maybe it can solve some of your deployment build issues since it helped me few times. I do not recall if it was for that same issue you are having right now but it is worth a shot.
That is for continuous integration and more for the installing of packages not the build process. I think I currently use npm install --production or something close to that to handle the install.
You are right. But there are differences in ci and install so I wanted to point that out. You can read all about differences here https://docs.npmjs.com/cli/ci
I'm trying to avoid having to run npm run prod locally to compile js and css before deploying.
Understood. You can do that on envoyer.io or forge.laravel.com
I'm thinking that should just build on the server but idk.
Yes it should. You can easily do that with deployment hooks on envoyer.io or deploy script on forge.laravel.com
Am I misunderstanding what npm ci does? Would you mind providing a bit more context please?
Read everything above 🤣
Kidding aside you are not missing something. Just pointing out npm ci cause not so many know about it, and didn't commented much about npm run prod since you can easily run it on production with mentioned two deployment tools.
In short, the main differences between using npm install and npm ci are:
- The project must have an existing package-lock.json or npm-shrinkwrap.json.
- If dependencies in the package lock do not match those in package.json, npm ci will exit with an error, instead of updating the package lock.
- npm ci can only install entire projects at a time: individual dependencies cannot be added with this command.
- If a node_modules is already present, it will be automatically removed before npm ci begins its install.
- It will never write to package.json or any of the package-locks: installs are essentially frozen.kk
Please or to participate in this conversation.