Setup for Next

This documentation explains how to get started with the integration in a Next 13 application.

Requirements

Something's missing?

If you don't have a Next 13 project yet, create one by following the official guide (opens new window). If you don't have a Bloomreach Content environment yet, we suggest you get in touch with Bloomreach and request a demo (opens new window).

Creating .npmrc file

In order to start working with our enterprise packages, add a .npmrc file with the following content to the root of your repository:

@vsf-enterprise:registry=https://registrynpm.storefrontcloud.io

Importing integration files

Vue Storefront ships with a CLI tool for CMS integrations which will import all of the frontend acceleration files into your project.

The CLI tool has been tested with a fresh Next 13 project without the App Router (opens new window).

To use the CLI, simply run the following command from the root of your project:

npx @vsf-enterprise/cms-cli bloomreach-content next

This will create (or overwrite) the following files in your project:

└── src
    ├── components
    │   └── cms
    │       ├── layout
    │       │   ├── Footer.tsx
    │       │   └── MegaMenu.tsx
    │       ├── page
    │       │   ├── Accordion.tsx
    │       │   ├── Banner.tsx
    │       │   ├── Card.tsx
    │       │   ├── Editorial.tsx
    │       │   ├── Gallery.tsx
    │       │   ├── Grid.tsx
    │       │   ├── Hero.tsx
    │       │   ├── NewsletterBox.tsx
    │       │   ├── ProductCard.tsx
    │       │   └── Scrollable.tsx
    │       └── wrappers
    │           ├── BRXComponent.tsx
    │           └── RenderComponent.tsx
    ├── pages
    │   ├── [[...slug]].tsx
    │   └── bloomreachLayout.tsx
    └── schemas
        ├── component-groups
        │   └── ...
        ├── components
        │   └── ...
        ├── content-types
        │   └── ...
        ├── folders
        │   └── ...
        ├── index.ts
        ├── layouts
        │   └── ...
        ├── menus
        │   └── ...
        └── synchronize.ts

If there is an index.tsx file in your src/pages directory - delete it. Otherwise - once you run your application - it will conflict with the [[slug]].tsx component responsible for rendering dynamic CMS pages.

Installing dependencies

The UI layer of the integration relies on Storefront UI and its dependencies. Follow the official guide (opens new window) to install the library in your project.

You will also need to install other integration dependencies such as SDKs (opens new window) provided by Bloomreach, axios (opens new window) and supplementary packages related to Storefront UI or agnostic CMS components. Run the following command to install them in your project:

# npm
npm install @bloomreach/spa-sdk @bloomreach/react-sdk axios -D @storefront-ui/typography @vsf-enterprise/cms-components-utils

# yarn
yarn add @bloomreach/spa-sdk @bloomreach/react-sdk axios -D @storefront-ui/typography @vsf-enterprise/cms-components-utils

Loading fonts

The default Storefront UI setup uses Google Fonts. One way to loading these fonts to your project is by importing them in the Next's global.css file:

@import url('https://fonts.googleapis.com/css2?family=Red+Hat+Display:wght@400;500;700&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Red+Hat+Text:wght@300;400;500;700&display=swap');

To complete the fonts setup, add the following Storefront UI typography (opens new window) configuration to your Tailwind config (opens new window) file:

const sfTypography = require('@storefront-ui/typography');

module.exports = {
  // ...
  plugins: [sfTypography],
  theme: {
    fontFamily: {
      sans: 'Red Hat Text, sans-serif',
    }
  }
};

Configuration

The last step is adding the bloomreachContent configuration to the runtimeConfig (opens new window) object of your next.config.js file. It should contain the name of your Bloomreach Content environment and the name of the channel you want to fetch the data from Both properties are used by the useBloomreachContent composable to configure the HTTP client.

module.exports = {
  // ...
  publicRuntimeConfig: {
    bloomreachContent: {
      environmentName: 'vuestorefront',
      channel: 'en'
    }
  }
}

Good to know

Keeping those properties in the main framework configuration file can be considered a good practice but is not mandatory. Especially with the channel property - most likely you will want to bind it with you application's i18n setup. In such a case, the channel would be dynamically evaluated at runtime.

What next?

Now your frontend application has the scaffolding required to display dynamic CMS components. However, there is one more thing left - setting up Vue Storefront's SDK for Bloomreach Content.