lukethacoder / lwrjs-lwc-module-provider

⚡ An opinionated edit to the @lwrjs/lwc-module-provider package to add support for namespaces and multi directory modules (via @lukethacoder/lwc-module-resolver)

Home Page:https://npmjs.com/package/@lukethacoder/lwrjs-lwc-module-provider

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

@lukethacoder/lwrjs-lwc-module-provider

⚡ An opinionated edit to the @lwrjs/lwc-module-provider package to add support for namespaces and multi directory modules (via @lukethacoder/lwc-module-resolver)

Install

pnpm add @lukethacoder/lwrjs-lwc-module-provider

Edit your lwr.config.json file to include the module.

{
  "lwc": {
    "modules": [],
  },
  "moduleProviders": [
    "@lwrjs/label-module-provider",
    "@lwrjs/app-service/moduleProvider",
    "@lukethacoder/lwrjs-lwc-module-provider",
    "@lwrjs/npm-module-provider"
  ],
  "routes": []
}

Custom Namespace Directories

The heavy lifting of the enhancements come from the @lukethacoder/lwc-module-resolver package. Below is a snippet of the docs from that package.

Instead of assuming the namespace based on the folder structure, you can declaratively set namespaces to directories. Automatic namespacing is still enabled.

The primary driver for this is the on platform folder structure conflicting with the standard open source folder structure.

Multiple directory per namespace is also supported. This is great for package developers who wish to break up their code into smaller packages but still have the benefits of a local dev server.

{
  "modules": [
    {
      "dir": "src/modules"
    },
    { 
      "dir": "force-app/main/default/lwc",
      "namespace": "c" 
    }
  ]
}

This example shows how you can assign the c namespace to the default salesforce LWC folder, whilst still keeping the standard config for folder based namespacing.

Multi Directory Namespacing

Multiple directory per namespace has also been added. This is great for package developers who wish to break up their code into smaller packages but still want to have the benefits of a local dev server.

{
  "modules": [
    {
      "dir": "src/modules"
    },
    { 
      "dir": "force-app/main/default/lwc",
      "namespace": "c" 
    },
    {
      "dirs": [
        "force-app/ui-account-flow/default/lwc",
        "force-app/ui-shared/default/lwc"
      ],
      "namespace": "ui"
    }
  ]
}

This example shows how you can assign the ui namespace to multiple source folders, whilst still keeping the standard config for folder based namespacing.

NOTE: This package aims to open up current imitations enforced by open source LWC and on-platform Salesforce development. This is done purely to make your life as a developer easier and is not intended to be used as a part of a production build. These enhancements may allow you to do things that will NOT work on-platform.

About

⚡ An opinionated edit to the @lwrjs/lwc-module-provider package to add support for namespaces and multi directory modules (via @lukethacoder/lwc-module-resolver)

https://npmjs.com/package/@lukethacoder/lwrjs-lwc-module-provider

License:MIT License