Sub topic 7
The configuration file
This chapter assumes you know basic XML syntax and have read the earlier chapters on the HTML template and the JavaScript class. You should also know that @api makes a class property public.
What the file does
Every Lightning web component bundle needs one configuration file. Its name is the bundle name plus .js-meta.xml, for example greetingCard.js-meta.xml. The HTML, JavaScript and CSS files describe what the component shows and does. The configuration file describes how Salesforce treats the component: which API version it uses, whether tools can see it, and where it can be placed.
Deployment fails if the file is missing or if its base name differs from the folder name.
A complete example
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>60.0</apiVersion>
<isExposed>true</isExposed>
<masterLabel>Greeting Card</masterLabel>
<targets>
<target>lightning__AppPage</target>
<target>lightning__RecordPage</target>
</targets>
<targetConfigs>
<targetConfig targets="lightning__AppPage">
<property name="name" type="String" default="World" />
</targetConfig>
</targetConfigs>
</LightningComponentBundle>The elements
| Element | Purpose |
|---|---|
| `apiVersion` | The Salesforce API version the component runs against. It is required. |
| `isExposed` | When `true`, the component appears in Lightning App Builder, Experience Builder and similar tools. |
| `masterLabel` | The name shown to administrators in those tools. If you omit it, the component name is used. |
| `targets` | The page types and containers where the component may be placed. |
| `targetConfigs` | Settings that apply to specific targets, such as editable properties. |
apiVersion
Salesforce releases a new API version three times a year. A component keeps the version it was saved with, so its behavior does not change unexpectedly when the platform updates. Raise the number deliberately when you want newer behavior.
isExposed
This flag controls visibility to builder tools, not whether the component works. A component with isExposed set to false can still be used inside another component's template. It just cannot be dragged onto a page by an administrator.
Targets and target configs
A component can only be placed on a target you list. A component listed only under lightning__AppPage will not appear in the record page editor. The next chapter covers the available targets in detail.
A property inside targetConfig adds a field to the builder's property panel. Its name must match a public property in the JavaScript class. Here, name="name" pairs with @api name in greetingCard.js. The targets attribute on targetConfig must also name a target from the main targets list.
Common errors
- File name mismatch.
greeting-card.js-meta.xmlorGreetingCard.js-meta.xmlin agreetingCardfolder breaks the deployment. The base name must match the folder exactly, including case. - Component missing from App Builder. Check
isExposedfirst. Then check that the page type you are editing appears intargets. - Property missing from the panel. Confirm that the JavaScript property has
@apiand that the spelling matches thepropertyname. - Deployment error about a property. The
typevalue must be one the target supports, such asString,IntegerorBoolean. A wrong target name intargetConfigalso causes an error.
Checking your work
After you edit the file, deploy the bundle and open a page in the builder. If the component or its property is missing, work through the list above in order. Most problems come from the name, isExposed, or the target list.
Exercise
A teammate deploys a component named orderSummary successfully, but it does not appear in the component list when editing a Record Page in Lightning App Builder. The meta file has isExposed set to true and one target, lightning__AppPage. What should they change?
Show answer
Add lightning__RecordPage to the targets list. The component is exposed, but it is only allowed on App Pages. Redeploy and the component will appear in the Record Page editor.