When using pnpm as your package manager, please add the following to your pnpm-workspace.yaml file:
minimumReleaseAge: 1440 # 1 day
minimumReleaseAgeExclude:
- "@nobears-front-end/nuxt-statamic"
- "@nobears-front-end/nuxt-mapbox"
- "@nobears-front-end/eslint"
- "@nobears-front-end/utils"
- "@nobears/ui"
Upgrade Nuxt version to at least v4.1.0
npx nuxi@latest upgrade --dedupe
Update the directory structure to the new Nuxt 4 structure.
Take a look at the Nuxt 4 directory structure for more information.
nuxt.config.tsRemove srcDir, experimental and update any relative paths to the new directory structure.
export default defineNuxtConfig({
// ...
srcDir: 'src/', experimental: {} // ...
});
Be sure to remove old path references from tailwind.config.js
module.exports = {
content: [
`./src/**/*.{vue,js,ts}`, `./app/**/*.{vue,js,ts}`, ],
};
Be sure to update the nuxt modules to the latest version that support Nuxt 4.
Among others:
@nuxt/eslint@nuxt/fonts@nuxt/image@nuxt/icon@nuxt/scripts@nuxtjs/seoFollow the I18n migration guide to update your I18n configuration.
And update your nuxt.config.ts file:
export default defineNuxtConfig({
// ...
i18n: {
// ...
langDir: "", vueI18n: "", restructureDir: true, },
});
Follow the Nuxt 4 TypeScript migration guide to update your TypeScript configuration.
Remove the server/tsconfig.json file.
And update your tsconfig.json file:
{
// ...
"extends": "./.nuxt/tsconfig.json", "files": [], "references": [ { "path": "./.nuxt/tsconfig.app.json" }, { "path": "./.nuxt/tsconfig.server.json" }, { "path": "./.nuxt/tsconfig.shared.json" }, { "path": "./.nuxt/tsconfig.node.json" } ]}
@unhead/vuepnpm remove @unhead/vue
@nobears/statamic-nuxt-theme.npmrcRemove and add the following lines to your .npmrc file:
# @nobears/statamic-nuxt-theme (53506017)# @nobears/nuxt-statamic (52687963)# @nobears-front-end:registry=https://git.nobears.nl/api/v4/packages/npm/
//gitlab.com/api/v4/projects/53506017/packages/npm/:_authToken=${GITLAB_TOKEN}//gitlab.com/api/v4/projects/52687963/packages/npm/:_authToken=${GITLAB_TOKEN}//git.nobears.nl/:_authToken=${GIT_NOBEARS_TOKEN}statamic-nuxt-theme packageRun the following command to remove the old statamic-nuxt-theme package:
pnpm remove @nobears/statamic-nuxt-theme
Be sure to remove the extends configuration from your nuxt.config.ts file.
export default defineNuxtConfig({
// ...
extends: ['@nobears/statamic-nuxt-theme'] // ...
});
By removing the statamic-nuxt-theme package, you will also remove some packages. You can install them again by running the following command:
pnpm add -D @nuxt/fonts @nuxt/icon @nuxt/image @nuxtjs/seo @nuxtjs/tailwindcss @tailwindcss/typography @gtm-support/vue-gtm @nobears/ui
And add them to your nuxt.config.ts file:
export default defineNuxtConfig({
// ...
modules: [
'@nuxtjs/tailwindcss', '@nuxt/fonts', '@nuxtjs/seo', '@nuxt/image', '@nuxt/icon', '@nobears/ui', ],
});
Update your nuxt.config.ts file to add the gtm support:
export default defineNuxtConfig({
// ...
runtimeConfig: {
public: {
gtmId: process.env.NUXT_PUBLIC_GTM_ID, }
},
});
Create a new file app/plugins/gtm.client.ts and add the following code:
import { createGtm } from '@gtm-support/vue-gtm'
export default defineNuxtPlugin((nuxtApp) => {
const { gtmId } = useRuntimeConfig().public
const siteConfig = useSiteConfig()
if (siteConfig.env === 'staging' || siteConfig.env === 'production') {
if(!gtmId) {
console.error('No NUXT_PUBLIC_GTM_ID found in environment file.')
return
}
}
if(gtmId) {
nuxtApp.vueApp.use(createGtm({
id: gtmId,
defer: true, // Speed up page load
compatibility: false,
enabled: true,
debug: false,
loadScript: true,
vueRouter: useRouter(),
trackOnNextTick: false,
}))
}
})
Add the following line to your .env.example file:
NUXT_PUBLIC_GTM_ID=GTM-XXXXXXX
tailwind.config.jsAdd the missing @tailwindcss/typography plugin.
module.exports = {
// ...
plugins: [
require('@tailwindcss/typography'), ],
};
nuxt-statamic moduleTake a look at the installation guide to install the new nuxt-statamic module.
And update your nuxt.config.ts file:
export default defineNuxtConfig({
// ...
modules: [
'@nobears-front-end/nuxt-statamic', ],
// ...
statamic: {
navigations: [
// ...
{
handle: 'footer',
fields: 'title,links', fields: ['title', 'links'], },
]
// collections have been deprecated
collections: []
// sitemap is now part of the seo config option
// (setting seo to true will automatically enable the sitemap)
sitemap: true, seo: true, },
// ...
seo: { redirectToCanonicalSiteUrl: true, },});
You will now need to use the useStatamicPageErrorHandler composable to handle the errors from the useStatamicPage composable.
<script setup lang="ts">
const { data, error } = await useStatamicPage();
useStatamicPageErrorHandler(error);</script>
We simplified the API for the StatamicBlock component to make it easier to use. However, if you don't feel like updating your components, you can add the following to have the same functionality as before:
<template>
<component
:is="resolveComponent(toPascalCase(block.type))"
v-for="block in data?.blocks"
:key="block.id"
:block="block"
/>
<!-- Adding the background image for backwards compatibility can be done like so -->
<component
v-for="block in data?.blocks"
:key="block.id"
:is="resolveComponent(toPascalCase(block.type))"
:block="block"
:style="{
backgroundImage: block.background_image?.permalink ? `url('${block.background_image?.permalink}')` : undefined,
backgroundSize: 'cover',
backgroundRepeat: 'no-repeat',
}"
/>
</template>
<script lang="ts">
import type { StatamicBlockProps, TextField } from "@nobears-front-end/nuxt-statamic";
export type TextImageProps = StatamicBlockProps<{
title: TextField;
// ...
}>;
</script>
<script setup lang="ts">
const props = defineProps<TextImageProps>();
</script>
<template>
<StatamicBlock :block="props.block">
<!-- Content here -->
</StatamicBlock>
</template>
For more information on how the spacing etc. is controlled, take a look at the Adding custom spacings section.
@import "tailwindcss";
@import "@nobears-front-end/nuxt-statamic";
@theme { --spacing-statamic-block-small--md: --spacing(20); /* Override the default spacing for the small block */}
@layer base {
/* list the bg colors that are used in statamic blocks like so */
[data-bg-color=''] { background-color: var(); }}