Skip to content

Setup

Prerequisites

To follow this guide, it is expected you have node, pnpm and sfdx installed as well as a SFDX Project setup with a valid lwc.config.json file.

  1. Install the package

    Run the following command in your terminal from the root of your SFDX Project to install LWC Garden:

    Terminal window
    pnpm add @lwc-garden/core
  2. Create a garden.config.js file

    import lwrConfig from './lwr.config.json' assert { type: 'json' }
    /**
    * @type {import('@lwc-garden/core/types').GardenConfig}
    */
    const CONFIG = {
    // lwc.config.json modules type
    modules: [...lwrConfig.lwc.modules],
    }
    export default CONFIG

    This is the bare minimum configuration required to get LWC Garden working. This imports your module configuration from your existing lwc.config.json file.

    Don’t forget to add the garden config to your lwr.config.json file:

    lwr.config.json
    {
    "lwc": {
    "modules": [
    {
    "dir": "./.garden/components",
    "namespace": "garden"
    },
    {
    "dir": "./force-app/main/default/lwc",
    "namespace": "c"
    }
    ]
    },
    "moduleProviders": [
    "@lwrjs/label-module-provider",
    "@lwrjs/app-service/moduleProvider",
    "@lukethacoder/lwrjs-lwc-module-provider",
    "@lwrjs/npm-module-provider"
    ],
    "routes": [
    {
    "id": "app",
    "path": "/",
    "rootComponent": "garden/app",
    "layoutTemplate": "./.garden/layouts/index.html",
    "bootstrap": {
    "syntheticShadow": true
    }
    }
    ]
    }
  3. Run the local dev server

    When working locally, the development server lets you preview your work and automatically refreshes your browser when you make changes.

    Run the following from the root of your SFDX Project:

    Terminal window
    npx @lwc-garden/core dev

    This will log a message to your terminal with the URL of your local preview. Open this URL to start browsing your LWCs.