Overview
The Next.js boilerplate for decoupled/ headless WordPress applications is a tool provided by WordPress VIP. It is designed to assist in creating decoupled WordPress sites using Next.js. Although not required for Node.js applications on VIP, this boilerplate helps to solve common use cases for decoupled WordPress applications. It requires the VIP decoupled plugin bundle to be installed and activated on the WordPress backend.
Features
- Next.js 13
- Fetch data with Apollo and WPGraphQL
- Seamless previewing
- Easy mapping of Gutenberg blocks to React components and integration with design systems
- Automatic code generation from GraphQL queries
- Optional TypeScript support
Installation
To get started with the Next.js boilerplate, follow these steps:
- Install the necessary dependencies.
- Configure the local installation of WordPress.
- Start the Next.js development server.
Install Dependencies
- Install
wp-env
using the provided instructions. - In the root directory of the repository, start and configure WordPress.
Note: The boilerplate project does not support plain permalinks.
Configure Local Installation
- Run the Next.js development server.
You can now access the Next.js front-end at http://localhost:3000
and the WordPress backend at http://localhost:8888/wp-admin
. Use the default credentials for the admin account.
Configure Remote Environment
Update the following environment variables in the .env
file:
NEXT_PUBLIC_GRAPHQL_ENDPOINT
: The full URL of your WPGraphQL endpoint.NEXT_PUBLIC_SERVER_URL
: The full URL of the Next.js site.
Add any additional environment variables as needed. The .env.production
file contains the working remote environment settings for testing against a live VIP WordPress backend.
Note: The boilerplate project does not support plain permalinks. Refer to the Permalink Setup section for supported configurations.
You should also review the vip.config.js
file for additional configuration options.
Development Server
Start the development server with hot-reloading at http://localhost:3000
.
Production Build
To test your production build locally, use the same commands that will be executed when your application runs on WordPress VIP. The build
directory is added to the .gitignore
file to avoid build artifacts in the repository. Instead, the build will be automatically run whenever you push code changes.
Previewing
Preview unpublished posts or updates to published posts by clicking the “Preview” button in the WordPress backend.