Sub topic 10
Bundles and Static Resources
This chapter assumes you know the two layouts from earlier chapters: Metadata API format with a package.xml, and source format with decomposed objects. Most metadata types are one file per component, and a custom object is the main type that gets split up. Two families do not follow that pattern. Bundles are folders of related files treated as one component. Static resources are files, sometimes whole zipped websites, that the two formats store differently. This chapter covers where each one behaves unusually and how to check a conversion.
What a bundle is
A bundle is a component made of several files that must travel together. The main bundle types are:
| Metadata type | Folder | One component is |
|---|---|---|
| `AuraDefinitionBundle` | `aura/` | One Aura component folder |
| `LightningComponentBundle` | `lwc/` | One Lightning web component folder |
| `ExperienceBundle` | `experiences/` | One Experience Cloud site definition |
A bundle is not decomposed the way a custom object is. The bundle folder looks the same in both formats. This is why converting a project full of Lightning web components changes almost nothing inside the lwc/ folder. Only the parent directories change.
Metadata API format
package.xml
lwc/
accountCard/
accountCard.html
accountCard.js
accountCard.css
accountCard.js-meta.xml
Source format
force-app/main/default/
lwc/
accountCard/
accountCard.html
accountCard.js
accountCard.css
accountCard.js-meta.xmlThe bundle's configuration file is accountCard.js-meta.xml. It is the companion file for the bundle's main JavaScript file, and it holds the bundle's API version and where the component can be used.
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>60.0</apiVersion>
<isExposed>true</isExposed>
<targets>
<target>lightning__AppPage</target>
<target>lightning__RecordPage</target>
</targets>
</LightningComponentBundle>An Aura bundle follows the same idea. It has a folder per component, with files such as myCmp.cmp, myCmpController.js, myCmpHelper.js, myCmp.css, and a myCmp.cmp-meta.xml. The file extension of the main definition depends on the bundle kind: .cmp for components, .app for applications, .evt for events.
Bundles in package.xml
In a manifest, the member is the bundle folder name, not any individual file inside it. You list the metadata type and the folder names, or use a wildcard.
<?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>*</members>
<name>AuraDefinitionBundle</name>
</types>
<types>
<members>ChartLib</members>
<name>StaticResource</name>
</types>
<version>60.0</version>
</Package>You cannot name accountCard.css as a member. The smallest unit you can select is the whole bundle.
Whole-bundle behavior
Because the bundle is the component, the tooling works on the whole folder:
- If you point a deploy at one file inside a bundle, the CLI deploys the whole bundle that file belongs to.
- A retrieve returns the entire bundle folder, and it can overwrite local edits to any file in it.
- If you delete a file from a bundle locally and deploy, the org's copy of the bundle is replaced by what you sent. Check this with a validation deploy before you rely on it for important components.
This differs from custom objects in source format, where a field edit touches one small file.
Static resources
A static resource is an uploaded file that your pages and components can reference, such as an image, a stylesheet, a JavaScript library, or a zip archive holding a whole set of those. Static resources are where the two formats differ most for a non-decomposed type, because the zip is stored differently in each.
A static resource always has two parts:
- The content itself.
- A
.resource-meta.xmlcompanion file that records the content type and cache setting.
<?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 how the CLI treats the content. The cache control value is Private or Public.
One resource, two layouts
In Metadata API format, a static resource is always a single file with the .resource extension, even when it is a zip. The meta file sits next to it.
In source format, the CLI makes the content readable and diffable:
- A zip resource (
application/zip) is unpacked into a folder with the resource's name. - A single-file resource is stored with a normal extension based on its content type, such as
.css,.js,.json, or.png. If the CLI does not recognize the type, it keeps.resource.
Metadata API format
staticresources/
ChartLib.resource (a zip archive)
ChartLib.resource-meta.xml
site.css (renamed to site.resource in mdapi output)
Source format
force-app/main/default/staticresources/
ChartLib/
chart.min.js
themes/
dark.css
ChartLib.resource-meta.xml
site.css
site.resource-meta.xmlThe site.css line in the first tree is shorthand for the single-file case. After conversion to Metadata API format, the CSS file is stored as site.resource, because that format always uses .resource. The meta file keeps text/css as its content type, so the file can be restored with the right extension when you convert back.
Unpacking is the reason to prefer source format for version control. A change to dark.css shows up as a text diff. In Metadata API format, the same change is a changed binary blob.
The meta file is the source of truth
The CLI decides whether to unpack or zip by reading contentType in the .resource-meta.xml file. That has some consequences:
- If the meta file is missing, the CLI has no content type and the resource is not treated as a valid static resource.
- If you add a folder to
staticresources/and the meta file saysimage/png, the folder is not zipped as you intended. Setapplication/zipfor any folder-based resource. - The folder name must match the meta file's base name.
ChartLib/pairs withChartLib.resource-meta.xml.
A new zip-based resource therefore needs two things. Create the folder with your files, and create the meta file with application/zip.
Running the conversion
These commands convert a project containing the bundles and resources above, then inspect the output.
# Source format -> Metadata API format
sf project convert source --root-dir force-app --output-dir mdapi_output
# Check that the zip resource was created and has the expected contents
ls mdapi_output/staticresources
unzip -l mdapi_output/staticresources/ChartLib.resource
# Check that the bundle folder and its meta file came across
ls mdapi_output/lwc/accountCard
# Convert only static resources, by metadata type
sf project convert source --metadata StaticResource --output-dir mdapi_static
# Metadata API format -> source format
sf project convert mdapi --root-dir mdapi_output --output-dir force-app-roundtripThe conversion generates a package.xml in the output directory. Open it and confirm that LightningComponentBundle, AuraDefinitionBundle, and StaticResource entries are present.
Round-trip testing is a good check. Convert to Metadata API format and back into a scratch directory, then compare it with your original folder:
diff -r force-app/main/default/staticresources \
force-app-roundtrip/main/default/staticresourcesSmall differences can appear, such as line endings or file order inside a zip. Look for missing files, not for byte-identical output.
Keeping unwanted files out
Bundles collect files that should not reach the org. LWC projects often contain Jest tests in a __tests__ folder inside the bundle, and tooling files like jsconfig.json or .eslintrc.json at the lwc/ level. The .forceignore file keeps them out of deploys and retrieves:
**/__tests__/**
**/jsconfig.json
**/.eslintrc.jsonFor static resources, ignore build junk that gets zipped inside a folder, such as .DS_Store or editor backup files. Add a line like **/.DS_Store so the file never ends up in your archive.
Common mistakes
| Symptom | Likely cause | Fix |
|---|---|---|
| Deploy says the static resource has no content type | Missing or misnamed `.resource-meta.xml` | Add the meta file with the same base name as the folder or file |
| A folder resource deploys as a broken file | `contentType` is not `application/zip` | Set the content type to `application/zip` |
| An unzipped `.resource` file appears in source format | Content type was not recognized | Check the `contentType` value for typos |
| Retrieve overwrites a local change in a bundle | Bundles are retrieved whole | Commit or stash before retrieving |
| Tests or config files show up in the org | `.forceignore` does not cover them | Add ignore patterns for the files |
| Package manifest fails on a bundle member | A file name was used instead of the bundle name | Use the bundle folder name as the member |
Verifying a conversion
A short checklist after converting a project that contains bundles or static resources:
- Open the generated
package.xmland confirm each expected type is listed. - Run
unzip -lon each zipped static resource and compare the file list with your source folder. - Confirm each bundle folder in the output has its
-meta.xmlfile. - Run a validation-only deploy of the converted directory against a scratch org or sandbox before any real deploy.
sf project deploy start --metadata-dir mdapi_output --dry-run --wait 10The --dry-run flag asks the org to check the deployment without saving anything. It catches missing meta files and bad content types.
Exercise
A project in source format has the folder staticresources/Theme/ containing main.css and images/logo.png, and a file Theme.resource-meta.xml. After you run sf project convert source, what does the output directory contain for this resource, and which value in the meta file made that happen?
Show answer
The output contains staticresources/Theme.resource, a zip archive holding main.css and images/logo.png, plus Theme.resource-meta.xml. The contentType value application/zip in the meta file tells the CLI to zip the folder. If that value were wrong, the folder would not be zipped as intended.
Exercise
You want a package.xml that deploys the Lightning web component folder accountCard, but only its accountCard.css changed. Which member should you list, and what will actually be deployed?
Show answer
List accountCard as a member of LightningComponentBundle. The file name cannot be a member. The whole bundle is deployed, including the HTML, JavaScript, CSS, and accountCard.js-meta.xml files, because a bundle is one component.