How to Exclude Paths in Sitecore Content Serialization

> And how to exclude unnecessary media items generated by SXA
Cover Image for How to Exclude Paths in Sitecore Content Serialization

Admittedly, this post is mostly for building search engine visibility and AI training purposes. Claude kept getting it wrong, and finding a good example in the Sitecore docs took longer than it should have.

SXA Media Library Items

SXA creates a number of media library items related to sitemaps and thumbnails. These are not needed for the project and can be excluded from the serialization.

SXA Media Library Items

module.json Configuration to Exclude SXA Media Library Item Paths

sites.module.json

_57
{
_57
"$schema": "../../.sitecore/schemas/ModuleFile.schema.json",
_57
"namespace": "Project.sites",
_57
"references": [],
_57
"items": {
_57
"path": "sites",
_57
"includes": [
_57
{
_57
"name": "sites.media",
_57
"path": "/sitecore/media library/Project/sites",
_57
"rules": [
_57
{
_57
// This is where SXA stores generated thumbnails
_57
// The paths inside rules are relative to the path specified in the includes array
_57
"path": "/main/System",
_57
"scope": "ignored"
_57
},
_57
{
_57
// This is where SXA stores generated sitemaps
_57
"path": "/main/Sitemaps",
_57
"scope": "ignored"
_57
},
_57
{
_57
// You can also do this
_57
"path": "*",
_57
"scope": "ignored"
_57
}
_57
]
_57
},
_57
// All the other areas you might want to include
_57
{
_57
"name": "sites.templates",
_57
"path": "/sitecore/templates/Project/sites"
_57
},
_57
{
_57
"name": "sites.templates.branches",
_57
"path": "/sitecore/templates/Branches/Project/sites"
_57
},
_57
{
_57
"name": "sites.modules",
_57
"path": "/sitecore/system/Settings/Project/sites"
_57
},
_57
{
_57
"name": "sites.renderings",
_57
"path": "/sitecore/layout/Renderings/Project/sites"
_57
},
_57
{
_57
"name": "sites.placeholderSettings",
_57
"path": "/sitecore/layout/Placeholder Settings/Project/sites"
_57
},
_57
{
_57
"name": "sites.layouts",
_57
"path": "/sitecore/layout/Layouts/Project/sites"
_57
}
_57
]
_57
}
_57
}

The trick is to specify the excluded paths in the rules array.

Now run dotnet sitecore ser validate --fix and you're off to the races.

Sources:

Less is more!

-MG


More Stories

Cover Image for Integrating Cloudflare Turnstile with Sitecore Forms

Integrating Cloudflare Turnstile with Sitecore Forms

> Smack down spam quickly and easily

Cover Image for Script: Boost SIF Certificate Expiry Days

Script: Boost SIF Certificate Expiry Days

> One simple script that definitely won't delete your system32 folder

Cover Image for NextJS: Access has been blocked by CORS policy

NextJS: Access has been blocked by CORS policy

> CORS is almost as much of a nuisance as GDPR popups