I read here that the deployment including building upfront, can be done with this command:
netlify deploy --build
Thank you for that @hrishikesh.
This command worked a few times on my Windows machine. When it suddenly stopped working and failed with the error Error: Failed publishing static content
, I tried it on Linux, where the deployment through the Netlify CLI runs successfully every time.
Closing and opening all VS Code editor windows again can sometimes help the deployment work again on Windows.
Hopefully this may be of help for someone.