// ecosystem.config.js
module.exports = {
apps: [
{
name: "nextjs-pm2",
script: "node_modules/next/dist/bin/next",
args: "start server",
instances: "max",
exec_mode: "cluster",
},
],
};
# Makefile
.PHONY: deploy
deploy:
mkdir -p server
cp -r .next server
cp -r public server
# If you have .env files uncomment the following lines
# cp .env server
# cp .env.production server
pm2 reload ecosystem.config.js
Add server
to exclude
{
"exclude": ["node_modules", "server"]
}
yarn build && make deploy
You can add to package.json
{
"scripts": {
"deploy": "yarn build && make deploy"
}
}