Sub topic 10
Bundles and static resources
This chapter assumes you know the two layouts from earlier chapters: Metadata API format with package.xml, and source format with sfdx-project.json. It also assumes you have used sf project convert. Here you will see two component kinds that don't follow the one-file-per-component rule: bundles and static resources.
Bundles are folders, not files
A bundle is a single component made of several files that must travel together. Lightning Web Components (LWC) and Aura components are bundles. Each bundle is a folder, and the folder name is the component name.
lwc/
accountCard/
accountCard.html
accountCard.js
accountCard.css
accountCard.js-meta.xml
aura/
AccountPanel/
AccountPanel.cmp
AccountPanelController.js
AccountPanel.cmp-meta.xmlBoth formats use this shape, so conversion does not decompose or merge bundle files. The converter copies the folder and its contents.
In package.xml, a bundle is one member of one type. Name the folder, not the individual files:
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>accountCard</members>
<name>LightningComponentBundle</name>
</types>
<types>
<members>AccountPanel</members>
<name>AuraDefinitionBundle</name>
</types>
<version>60.0</version>
</Package>The type for LWC is LightningComponentBundle. The type for Aura is AuraDefinitionBundle. A deploy sends the whole bundle, so you can't deploy only the CSS file of a component.
Static resources are the exception
A static resource is an uploaded file that Salesforce serves, such as an image, a JavaScript library, or a zip of site assets. It has two files in either format: the content and a -meta.xml file. The -meta.xml file records the contentType and cacheControl values.
The layouts differ in how they store the content.
| Aspect | Metadata API format | Source format |
|---|---|---|
| Single file (for example a PNG) | `staticresources/Logo.resource` | `staticresources/Logo.png` |
| Zip archive | `staticresources/SiteKit.resource` (a zip file) | `staticresources/SiteKit/` (an unzipped folder) |
| Companion file | `Logo.resource-meta.xml` | `Logo.resource-meta.xml` |
In Metadata API format, the .resource extension hides the real file type. In source format, the CLI uses an extension that matches the contentType. For a zip, it expands the archive into a folder so Git can show file-level diffs. When you deploy, the CLI zips the folder again.
The companion file for a zip looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<StaticResource xmlns="http://soap.sforce.com/2006/04/metadata">
<cacheControl>Private</cacheControl>
<contentType>application/zip</contentType>
</StaticResource>The contentType value drives the behavior. If it says application/zip, source format expects a folder. If it says image/png, it expects a single file.
Common errors
- Wrong content type. If you edit the folder but leave
contentTypeasimage/png, the CLI treats the resource as a single file and the deploy fails or uploads the wrong content. Match the type to the content. - Missing companion file. A resource without its
.resource-meta.xmlis not recognized, so it is skipped or rejected. - Naming mismatch. The folder name must equal the static resource name, and the
-meta.xmlfile must use that same name. - Partial bundles. Deleting a file from a bundle folder locally and then deploying changes the whole bundle. Check
git statusbefore you deploy.
Check your understanding
Exercise
You retrieve a static resource named SiteKit whose contentType is application/zip into a source-format project. What do you expect to find under staticresources/, and what happens when you convert the project to Metadata API format?
Show answer
You find a folder named SiteKit containing the unzipped files, plus SiteKit.resource-meta.xml. Converting to Metadata API format zips the folder into SiteKit.resource and keeps SiteKit.resource-meta.xml next to it.