Deploy on Netlify

Add the export script

In order to publish on Netlify, we need to change a setting in the build command of Next.js. Open the package.json file and change the "build" script, adding && next export:

...
"scripts": {
"dev": "next dev",
"build": "next build && next export",
"start": "next start"
},

Create the Project

Access your Netlify account at app.netlify.com

Click on the "New site from Git" button, then authenticate to your Git provider and select the repository you created for this tutorial.

On the "Deploy settings" screen, leave all the default options for a Next.js project (`yarn build` command and `/out` publish directory), but click on "Show advanced" and use the "Add variable" button to add the two environment variables that you can find in your project .env file:

  • API_KEY, the secret key to access your APIs.
  • NEXT_PUBLIC_APP_ID, a string identifying your app. It is prefixed by "NEXT_PUBLIC" so that it will be accessible by the client (browser) app.
Environment variables on Netlify

Now, click the "Deploy site" button.

You will see "Site deploy in progress". Netlify will fetch the code from the Git repository and will start the build process. As soon as it finishes, you will see a green URL assigned by Netlify:

React Bricks deployed on Netlify

Congratulations! Your React Bricks website is up and running! 🎉🍻

Set up a build hook

The website will be rebuilt automatically by Netlify each time we push new commits from the git repository. We want the website to be rebuilt also when content is updated.

To do this we need to create a build hook on Netlify and put it into the React Bricks app settings. In this way your users will see a "Deploy now" button in React Bricks to rebuild the website when content is updated.

Click on "Site settings", then "Build & deploy" from the left sidebar. Scroll down to "Build Hooks". Click on "Add build hook".

Netlify deploy hook for React Bricks

Give a name to your hook, click on "Save". Then copy the hook URL.

Goto your React Bricks website (either local or the newly published one on Netlify), go to the Admin dashboard and click on the "App Settings" tab. Paste the deploy hook in the "Build Webhook URL" field and click "Save settings".

Save deploy hook to React bricks App settings

Now you see that you have a "Deploy now" button on the App Settings tab of React Bricks.

Click it and verify that it triggers a rebuild process on Netlify.

You are great! You just published your React Bricks app on Netlify!

Time to get points

What do you need to do to let editors deploy a static site when content changes?