Tailwind Logo

Create a new Headless SXA project

XM CloudHeadless SXA

Published: 2023-12-11

I have been using the Haedless SXA project included in the project, but is there any difference between this and the Next.js that has been offered before? This time, we will proceed to prepare and run the new Next.js application.

Check package.json

If you check the package.json of the JSS application you have been running, you will find the following information.

JSON
{
  "name": "sxastarter",
  "description": "Application utilizing Sitecore JavaScript Services and Next.js",
  "version": "21.4.0",
  "private": true,
  "config": {
    "appName": "sxastarter",
    "rootPlaceholders": [
      "jss-main"
    ],
    "sitecoreConfigPath": "/App_Config/Include/zzz",
    "graphQLEndpointPath": "/sitecore/api/graph/edge",
    "language": "en",
    "templates": [
      "nextjs",
      "nextjs-sxa",
      "nextjs-personalize",
      "nextjs-multisite"
    ]
  },

Templates include sxa, personalize and multisite as well as nextjs. Now let's create a new project.

Create a new Next.js project

This time we will work with the src directory path (containing sxastarter or rendering, etc.). This time, we will execute the following command

PowerShell
npx create-sitecore-jss

First, you will be prompted to confirm which template you wish to use. Here, select next.js.

newsxaproject01.png

We will then go on to confirm the path to install. In this case, we will proceed with nextjs.

newsxaproject02.png

Then we will go on to check the behavior during pre build, where we will answer Y. Next is the name of the app, this time renaming it sitecore-nextjs-app.

newsxaproject03.png

We will check the hostname of Sitecore, but we will proceed with the default this time. The data for the dictionary is Graphql, and we will select SSG.

Then the "Which template do you want to use? screen will appear. Here, select the same items as in Package.json above.

newsxaproject04.png

Once the above selections are made, the necessary processing is performed.

newsxaproject05.png

After a short while, a new Next.js app will be added to the project.

newsxaproject06.png

Settings are reflected in the new application.

Since little has been set up yet, please copy the following files from the old application

  • src\rendering\.env
  • src\rendering\src\components\Types.tsx
  • src\rendering\src\components\YouTube.tsx

Also, since the language is set in next.config.js, please change the following code

JSON
  i18n: {
    // These are all the locales you want to support in your application.
    // These should generally match (or at least be a subset of) those in Sitecore.
    locales: ['en', 'ja-JP'],
    // This is the locale that will be used when visiting a non-locale
    // prefixed path e.g. `/styleguide`.
    defaultLocale: jssConfig.defaultLanguage,
    localeDetection: false,
  },

The new application is now ready.

Operation check

Actually go to the nextjs folder and execute the following command

PowerShell
jss start:connected

After a short while, the application will start.

newsxaproject07.png

When I accessed the URL, I was able to view the page.

newsxaproject08.png

If you look at the package.json file, you will see that the version is newer.

newsxaproject09.png

Summary

In this article, we showed you how to launch a new Next.js application. In addition to that, we were able to change to the new version this time.

Tags