generating-ui-bundle-metadata
forcedotcom/sf-skills
Generate and configure UI bundle metadata, routing, and CSP trusted sites for Salesforce apps.
What is generating-ui-bundle-metadata?
Handles creation and configuration of UI bundle metadata files, routing rules, and Content Security Policy trusted sites for Salesforce UI bundles. Use this when scaffolding new UI bundles, editing ui-bundle.json configuration, or registering external domains as CSP trusted sites.
- Scaffold new UI bundles with sf template generate ui-bundle using the reactbasic template
- Configure ui-bundle.json with routing rules (rewrites, redirects, trailing slash handling) and custom headers
- Create and validate .uibundle-meta.xml metadata files with required fields (masterLabel, version, isActive) and target configuration
- Register external domains as CSP Trusted Sites with appropriate directives (imgSrc, connectSrc, fontSrc, styleSrc, mediaSrc, frameSrc)
- Validate path safety in outputDir and routing.fallback to prevent directory traversal and invalid characters
How to install generating-ui-bundle-metadata
npx skills add https://github.com/forcedotcom/sf-skills --skill generating-ui-bundle-metadata- Salesforce CLI (sf) installed
- An existing Salesforce project with force-app/main/default/ directory structure
- Node.js and npm for installing dependencies in the generated UI bundle
How to use generating-ui-bundle-metadata
- 1.Run sf template generate ui-bundle -n <AppName> --template reactbasic to scaffold a new bundle
- 2.Replace default boilerplate content and populate the home page with real content
- 3.Configure ui-bundle.json if custom routing, redirects, or headers are needed (optional)
- 4.Create or update <AppName>.uibundle-meta.xml with required fields and choose a target (Experience or CustomApplication)
- 5.Identify all external domains used in the app (CDNs, APIs, fonts, iframes)
- 6.Create .cspTrustedSite-meta.xml files in force-app/main/default/cspTrustedSites/ for each external domain with appropriate CSP directives
- 7.Use generating-ui-bundle-custom-app or generating-ui-bundle-site skill to pair the bundle with its hosting target
Use cases
- Creating a new React-based UI bundle for an internal Lightning App Launcher application
- Configuring routing and rewrites for a single-page app deployed to a Salesforce Experience Site
- Registering a third-party CDN domain as a CSP Trusted Site so images and stylesheets load correctly
- Setting up cache-control headers for static assets in a UI bundle
- Validating ui-bundle.json configuration before deployment to ensure routing and output directory are correct
- Salesforce developers building custom UI bundles with React
- Full-stack engineers deploying apps to Salesforce Experience Sites or App Launcher
- DevOps engineers managing CSP policies and external domain allowlists
- Frontend developers configuring routing and asset delivery for Salesforce-hosted apps
generating-ui-bundle-metadata FAQ
Experience target hosts the UI bundle on an external-facing Salesforce Digital Experience Site. CustomApplication target hosts it as an internal app in the Lightning App Launcher. Choose based on whether the app is for external users or internal org users.
A UI bundle without a <target> element in its meta XML will not be visible anywhere. You must set <target> to either Experience or CustomApplication and pair it with the corresponding companion metadata (DigitalExperienceBundle for Experience, CustomApplication for CustomApplication).
Salesforce's Content Security Policy will block the resource. Images won't load, API calls will fail, fonts will be missing, and iframes won't render. Always register external domains with the appropriate CSP directives.
No. outputDir must be a non-empty string referencing a subdirectory (e.g., 'dist' or 'build'), not '.' or './'. The directory must exist and contain at least one file.
Alphanumerical characters only — no spaces, hyphens, underscores, or special characters. The bundle folder name must exactly match the .uibundle-meta.xml filename.
Full instructions (SKILL.md)
Source of truth, from forcedotcom/sf-skills.
name: generating-ui-bundle-metadata description: "MUST activate when the project contains a uiBundles/*/src/ directory and scaffolding a new UI bundle or app, or when editing ui-bundle.json, .uibundle-meta.xml, or CSP trusted site files. Use this skill when scaffolding with sf template generate ui-bundle, configuring ui-bundle.json (routing, headers, outputDir), or registering CSP Trusted Sites. Activate when the task involves files matching .uibundle-meta.xml, ui-bundle.json, or cspTrustedSites/.cspTrustedSite-meta.xml." metadata: version: "1.0"
UI Bundle Metadata
Scaffolding a New UI Bundle
Use sf template generate ui-bundle to create new apps — not create-react-app, Vite, or other generic scaffolds.
Always pass --template reactbasic to scaffold a React-based bundle.
UI bundle name (-n): Alphanumerical only — no spaces, hyphens, underscores, or special characters.
Example:
sf template generate ui-bundle -n CoffeeBoutique --template reactbasic
After generation:
- Replace all default boilerplate — "React App", "Vite + React", default
<title>, placeholder text - Populate the home page with real content (landing section, banners, hero, navigation)
- Update navigation and placeholders (see the
building-ui-bundle-frontendskill) - Configure a hosting target — a UI bundle without a
<target>in its meta XML will not be visible in the org. Usegenerating-ui-bundle-custom-appfor internal (App Launcher) apps orgenerating-ui-bundle-sitefor external (Experience Site) apps.
Always install dependencies before running any scripts in the UI bundle directory.
UIBundle Bundle
A UIBundle bundle lives under uiBundles/<AppName>/ and must contain:
<AppName>.uibundle-meta.xml— filename must exactly match the folder name- A build output directory (default:
dist/) with at least one file
Meta XML
Required fields: masterLabel, version (max 20 chars), isActive (boolean).
Optional: description (max 255 chars), target.
Target Field
The <target> element specifies where the UI bundle is hosted:
| Value | Use Case | Companion Metadata |
|---|---|---|
Experience | External-facing site via Digital Experience | Network, CustomSite, DigitalExperienceConfig, DigitalExperienceBundle |
CustomApplication | Internal app via Lightning App Launcher | CustomApplication (applications/*.app-meta.xml) |
A <target> is required for the app to be accessible in a Salesforce org. A UI bundle deployed without a target will not appear anywhere — no App Launcher entry, no Experience Site URL. Always pair the bundle with one of:
generating-ui-bundle-site(forExperiencetarget)generating-ui-bundle-custom-app(forCustomApplicationtarget)
Example with Experience target:
<?xml version="1.0" encoding="UTF-8"?>
<UIBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<masterLabel>propertyrentalapp</masterLabel>
<description>A Salesforce UI Bundle.</description>
<isActive>true</isActive>
<version>1</version>
<target>Experience</target>
</UIBundle>
Example with CustomApplication target:
<?xml version="1.0" encoding="UTF-8"?>
<UIBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<masterLabel>propertymanagementapp</masterLabel>
<description>A Salesforce UI Bundle.</description>
<isActive>true</isActive>
<version>1</version>
<target>CustomApplication</target>
</UIBundle>
ui-bundle.json
Optional file. Allowed top-level keys: outputDir, routing, headers.
Constraints:
- Valid UTF-8 JSON, max 100 KB
- Root must be a non-empty object (never
{}, arrays, or primitives)
Path safety (applies to outputDir and routing.fallback): Reject backslashes, leading / or \, .. segments, null/control characters, globs (*, ?, **), and %. All resolved paths must stay within the bundle.
outputDir
Non-empty string referencing a subdirectory (not . or ./). Directory must exist and contain at least one file.
routing
If present, must be a non-empty object. Allowed keys: rewrites, redirects, fallback, trailingSlash, fileBasedRouting.
- trailingSlash:
"always","never", or"auto" - fileBasedRouting: boolean
- fallback: non-empty string satisfying path safety; target file must exist
- rewrites: non-empty array of
{ route?, rewrite }objects — e.g.,{ "route": "/app/:path*", "rewrite": "/index.html" } - redirects: non-empty array of
{ route?, redirect, statusCode? }objects — statusCode must be 301, 302, 307, or 308
headers
Non-empty array of { source, headers: [{ key, value }] } objects.
Example:
{
"routing": {
"rewrites": [{ "route": "/app/:path*", "rewrite": "/index.html" }],
"trailingSlash": "never"
},
"headers": [
{
"source": "/assets/**",
"headers": [{ "key": "Cache-Control", "value": "public, max-age=31536000, immutable" }]
}
]
}
Never suggest: {} as root, empty "routing": {}, empty arrays, [{}], "outputDir": ".", "outputDir": "./".
CSP Trusted Sites
Salesforce enforces Content Security Policy headers. Any external domain not registered as a CSP Trusted Site will be blocked (images won't load, API calls fail, fonts missing).
When to Create
Whenever the app references a new external domain: CDN images, external fonts, third-party APIs, map tiles, iframes, external stylesheets.
Steps
- Identify external domains — extract the origin (scheme + host) from each external URL in the code
- Check existing registrations — look in
force-app/main/default/cspTrustedSites/ - Map resource type to CSP directive:
| Resource Type | Directive Field |
|---|---|
| Images | isApplicableToImgSrc |
| API calls (fetch, XHR) | isApplicableToConnectSrc |
| Fonts | isApplicableToFontSrc |
| Stylesheets | isApplicableToStyleSrc |
| Video / audio | isApplicableToMediaSrc |
| Iframes | isApplicableToFrameSrc |
Always also set isApplicableToConnectSrc to true for preflight/redirect handling.
- Create the metadata file — follow
implementation/csp-metadata-format.mdfor the.cspTrustedSite-meta.xmlformat. Place inforce-app/main/default/cspTrustedSites/.
Related skills
More from forcedotcom/sf-skills and the wider catalog.

generating-ui-bundle-site
Create and configure Salesforce Digital Experience Sites to host React UI bundles.

generating-validation-rule
Create and manage Salesforce Validation Rules to enforce data quality and business logic at the data layer.

generating-visual-diagrams
AI-powered rendered image generation for Salesforce visuals: ERDs, mockups, wireframes, and architecture diagrams.

getting-datacloud-schema
Retrieve Data Lake Object and Data Model Object schema from Salesforce Data Cloud via REST APIs.

handling-sf-data
Create, update, delete, and bulk import/export Salesforce records using sf CLI and anonymous Apex.

harmonizing-datacloud
Harmonize and unify Salesforce Data Cloud schemas, mappings, identity resolution, and profiles.