What are the mandatory files required to create a standard Lightning Web Component?
Answer
Basics: A component lives in a folder under force-app/main/default/lwc/, for example lwc/accountCard/. The folder name is camelCase and every file inside uses the same base name: accountCard.html, accountCard.js, accountCard.js-meta.xml, and optionally accountCard.css. In markup the component is referenced as <c-account-card> (namespace c for the org's own code, kebab-case for the camelCase name). The HTML is the template, the JS holds the logic, and the XML tells the platform where the component may be used.
How it works:
- The JS file must
export defaulta class that extendsLightningElement. - By convention the engine pairs
accountCard.htmlwith the class and renders it. If no template exists and norender()method is defined, the component has no UI. That is legitimate for a pure service or utility module. - The meta file is required to deploy the bundle.
isExposedcontrols whether it appears in Lightning App Builder, Experience Builder or Flow, andtargetslists the places it may be dropped. - Optional files:
.css(scoped to the component),.svg(custom icon), a__tests__folder for Jest, and additional.jshelper modules imported withimport { x } from './helper'.
Advanced / deep dive: A bundle can hold multiple JS modules, so shared logic can be split into plain ES modules. A "service" bundle with only a JS file and meta file is imported by others with import { fn } from 'c/utils'. targetConfigs in the meta file define design-time properties for App Builder, mapped to fields. Flow screens need the target. Components used from record pages can restrict by . Bundle size and the count of imports affect load time, so keep helper modules lean. Visibility of a component to another namespace follows plus package access rules.