首页 > 解决方案 > How to 'npm run build' on the server regularly

问题描述

My webpage doesn't update contents too often, and users don't necessarily need to get the latest contents. So most pages are generated at server side, and serves static pages.

However, there will be database update. That should be visible on the web page. So I want how to 'npm run build' regularly while my server serves stably. How do I do that?

标签: javascriptnext.js

解决方案


The first thing that comes to mind for "regular" tasks that will be simple and won't require much setup is a corn job. You can add 'npm run build'(obliviously pointing to the right directory) to crontab with any schedule you want. Here's a link with samples on how to setup cron.

But as you need to build your app and even run DB updates, it will be much safer and better to use CI solution. There are hundreds of them but my advice is to use Buddy. It has a free plan and super easy to work with. With Buddy you can set up a pipeline that will SSH in your server and do the job. Or you can set up pipelines that will do all the actions at Buddy CI and then upload compiled files to the server.

Also, if we'd know what exactly 'npm run build' does, it will be easier to point for a more detailed answer.


推荐阅读