For any prebuild steps, just add the "prebuild" property to your package.json's "scripts" property:
{
...
"scripts": {
"build": "next build",
"postbuild": "node ./path-to/my-prebuild-script.mjs",
"dev": "next dev",
"start": "next start",
"lint": "next lint"
}
...
}