LWCLab lets you describe a Lightning Web Component in natural language and preview usable source code in seconds. The project couples a Lightning Web Runtime (LWR) single-page app with a lightweight Node API that can call either OpenAI or Google Gemini based on the model toggle in the UI.
LWable.webm
src/modules/app/shellrenders the chat-style UI you will use to describe the component you want (and now hosts the OpenAI/Gemini toggle next to the title).api/server.mjsruns on port 3001 and talks to the selected provider to generate HTML/JS/CSS for the preview.- The generated files land in
src/modules/gen/previewso the LWR runtime can immediately render the new component.
- Node.js 18 or newer (the project is pinned to Node 20.16.0 via Volta).
- npm for dependency management.
- At least one supported AI key:
OPENAI_API_KEYwith access to thegpt-4.1-minimodel.GEMINI_API_KEYwith access to thegemini-2.5-flashmodel. (You can provide both keys and switch in the UI.)
- Install dependencies:
npm install
- Create a
.envfile at the project root with the credentials you plan to use:Only one key is required, but supplying both lets you flip providers without editing env vars. Keep this file out of version control;OPENAI_API_KEY=sk-... GEMINI_API_KEY=ai-...
.gitignorealready excludes it.
- One command for both servers
This runs the LWR dev server on http://localhost:3000 and the API server on http://localhost:3001.
npm run start:all
Once both processes are up, open http://localhost:3000. Use the toggle beside LWC Generator to choose OpenAI or Gemini, enter a prompt in the chat panel, click Generate, and the preview pane will refresh with the latest component. The last conversation and code snapshot are cached in sessionStorage so a browser refresh keeps your progress.
- Generate a component so the preview pane shows the latest HTML/JS/CSS.
- Click Deploy to Salesforce in the preview header.
- Choose a Lightning web component name (letters, numbers, underscores; must start with a small letter) and tick the surfaces you want to expose (
lightning__AppPage,lightning__HomePage,lightning__RecordPage). - Enter your Salesforce username and password (append your security token if your org requires one).
- The server logs in with jsforce, bundles the generated source, and deploys it using the Metadata API.
Environment variables
SF_LOGIN_URL(optional): override the login endpoint (usehttps://test.salesforce.comfor sandboxes).SF_API_VERSION(optional): defaults to60.0if not set.SF_DEPLOY_TIMEOUT_MS(optional): override the deploy wait timeout (defaults to 300000 ms).
Credentials are sent only to your local API server and are never stored.
- Every time you generate, the files in
src/modules/gen/previeware overwritten. I've added them to.gitignoreso that they don't bug you on every refresh. - The API sanitises generated markup to enforce valid LWC semantics; check the terminal logs if a prompt fails.
- The UI remembers your model selection in
sessionStorage, so your provider choice survives refreshes.
- Missing API key? The API server will exit with provider-specific errors; double-check
.envand restart. - Model errors bubble up in the API console (either from OpenAI or Gemini); inspect the stack trace there first.
- Port clashes on 3000 or 3001? Stop the conflicting service or update the scripts in
package.jsonto use open ports.
- Chat UI to look more like Chatting.
- Download LWC Option.
- Deploy component to Salesforce Org.
- Use Structured Outputs
- Add more LLM providers (Gemini support via toggle)
- Upload your LWC to update