Module Unification


One of the primary use-cases for LWC is to allow Lightning Web Components inside the Salesforce's platform. This platform has some constrains around the folder structure and files names, and we will have to align with those constrains. Additionally, we will like to have a comprehensive structure that is easy to understand that easy to reasoning, and ideally, it can map to existing mechanism of resolution (e.g.: NPM).

This proposal is about the bundle interface, not about the internals of the bundle, which means that existing invariants about the bundle's internal behavior continue to be valid.


1. camelCase



Folder structure:

└── src
    └── modules
        ├── foo
        │   ├── list
        │   │   ├── list.html
        │   │   └── list.js
        │   └── listItem
        │       ├── listItem.html
        │       └── listItem.js
        └── lightning
            ├── button
            │   ├── button.html
            │   └── button.js
            ├── keyboardNav
            │   └── keyboardNav.js
            └── buttonGroup
                ├── buttonGroup.html
                └── buttonGroup.js

HTML Files:


JS Files:

import { something } from "foo/keyboardNav";

Compiled HTML Code:

import buttonGroup from "lightning/buttonGroup";
import button from "lightning/button";
import listItem from "foo/listItem";
import list from "foo/list";
function template() {
    // ...
export { template };


SFDX Compliance namespaces documentation can:

  1. Contain underscores
  2. Are case preserving though case-insensitive (eg customer registers Acme and the namespace can be referenced as acme or ACME in the various languages/tech)

The compiler can analyze apply the heuristic, and produce the following import statement:

import C1 from "mynamespace_foo/myComponent_bar";`

And the platform can readjust the module specifier to match the internal representation, (e.g.: MyNamespace_Foo/myComponent_bar) to match the canonical version for bundle in folder MyNamespace_Foo/myComponent_bar/. This does not affect the compiler in any way since's namespaces are technically case-insensitive.



Edge Cases

  1. Bundle name starting with UpperCase:

The compiler can analyze the double - in the name to apply the heuristic, and produce the following import statement:

import C1 from "foo/MyComponent";`