
Lightning Web Components (LWC) is Salesforce’s modern JavaScript-based framework designed for building fast, efficient, and reusable UI components. Every LWC you create is made up of a collection of files known as the LWC Bundle. Understanding these files is essential for any Salesforce developer working with Lightning experiences.
What Is an LWC Bundle?
An LWC Bundle is a folder that contains all the files required for a Lightning Web Component to function. Each file in the bundle has a specific role—such as defining the UI, handling logic, styling the component, configuring metadata, or exposing the component for use in Lightning App Builder.
Below is a detailed breakdown of each file present in an LWC bundle along with its purpose and example use cases.
Watch Our Video Tutorial
Main Components of the LWC Bundle
| File Name | Extension | Purpose |
|---|---|---|
| HTML Template | .html | Defines the UI, structure, and layout of the component. |
| JavaScript Controller | .js | Handles the component's logic, events, and interactions. |
| Meta Configuration | .js-meta.xml | Declares where the component can be used (App Builder, Record Page, Community, etc.). |
| Styling File | .css | Applies component-specific styling. |
| SVG Icon | .svg | Used as the component icon in App Builder. |
| Documentation | .md | Provides notes or instructions for other developers. |
| Unit Test File | .test.js | Jest test cases to validate component functionality. |
Detailed Explanation of Each Bundle File
1. HTML File (.html)
This file defines the visual part of the component using standard HTML and template syntax. You can include loops, conditions, data binding, and event handlers.
Example: <template> <h1>Hello {name}!</h1> </template> 2. JavaScript File (.js)
The JavaScript file controls the component’s logic. It handles user actions, data fetching, wire adapters, event dispatching, and computations.
import { LightningElement, track } from 'lwc'; export default class HelloWorld extends LightningElement { name = 'Peoplewoo Skills'; } 3. Meta XML File (.js-meta.xml)
The meta configuration file defines where the component can be used and whether it is exposed to Lightning App Builder.
<?xml version="1.0" encoding="UTF-8"?> <LightningComponentBundle> <apiVersion>60.0</apiVersion> <isExposed>true</isExposed> <targets> <target>lightning__RecordPage</target> <target>lightning__AppPage</target> </targets> </LightningComponentBundle> 4. CSS File (.css)
Used to style your component. LWC offers component-level style isolation.
.example { color: blue; }
5. SVG Icon (.svg)
This file represents the component’s icon in App Builder or Experience Cloud.
6. Documentation File (.md)
Provides notes, instructions, and helpful tips for developers. Not required, but useful for teams.
7. Jest Test File (.test.js)
Contains unit test scripts written using Jest. Helps ensure your component works as expected.
Real-Life Example: How the LWC Bundle Works in a Project
Imagine you’re building a component that displays a list of Salesforce Contacts based on user selection. The HTML handles UI, the JS fetches Contact records via Apex, CSS styles the list, and the Meta file makes the component available on the Lightning Home Page. Together, these files create a complete and deployable LWC.
Why LWC Bundle Structure Matters
- Improves code organization
- Allows modular development
- Enhances reusability
- Makes deployment and testing easier
Frequently Asked Questions (FAQ)
Conclusion
Understanding the components of an LWC bundle is the first step toward becoming a skilled Salesforce developer. Each file plays a critical role in building efficient, modular, and scalable Lightning Web Components. With this knowledge, you're ready to start building real-world LWC projects and enhancing your Salesforce expertise.
More SFDC Resources
Start your SFMC journey today — join our Live Training
Need help? Chat with us on WhatsApp anytime.
Learn. Practice. Get Certified. Succeed with Peoplewoo Skills.
