Package structure
Thelit-starter-ts template uses the following layout:
outDir: "./" and rootDir: "./src", so src/my-element.ts compiles to my-element.js at the package root. This keeps import paths simple: consumers write import 'my-package/my-element.js'.
package.json
A minimalpackage.json for a published Lit component:
package.json
Key fields
type: "module" — Declares all .js files in the package as ESM. Required for native browser imports.
exports — Restricts which files consumers can import and maps entry points to their TypeScript types. Prefer this over main for new packages.
files — Allowlist of files to include in the published package. Do not publish src/ or test files.
customElements — Points to the Custom Elements Manifest file, used by editors and documentation tools.
Do not bundle lit — use peerDependencies
Do not includelit in your bundle or in dependencies. If you bundle Lit, consumers who also use Lit will ship two copies of the library, which breaks the custom element registry and wastes bytes.
Instead, declare lit as a peerDependency:
package.json
lit but excludes it from the library output.
TypeScript declaration files
Enabledeclaration and declarationMap in your tsconfig.json:
tsconfig.json
my-element.d.ts— type declarations consumed by TypeScript users of your packagemy-element.d.ts.map— maps declarations back to the original.tssourcemy-element.js.map— maps the compiled JS back to the original source
.d.ts and .d.ts.map files in the files list in package.json.
Bundling for demos with Rollup
For generating a standalone bundled demo (e.g. for a documentation site), thelit-starter-ts uses the following Rollup config:
rollup.config.js
This config is for bundling a demo — it includes
lit in the output via resolve(). For your library output, do not call resolve() on lit so that the peer dependency remains external.lit external in a library bundle:
rollup.config.js
Custom Elements Manifest
Thecustom-elements-manifest analyzer generates a JSON manifest describing your component’s API. This is read by tools like IDEs, documentation generators, and Storybook.
Install and configure the analyzer:
package.json:
package.json
Using lit-starter-ts as a template
The fastest way to start a publishable component is to clonelit-starter-ts:
TypeScript build
Pre-configured
tsconfig.json and tsc build step with declaration file output.Web Test Runner
Full test setup with Playwright launchers for Chromium, Firefox, and WebKit.
Rollup bundling
Rollup config for bundled demo output with terser minification.
Custom Elements Manifest
Analyzer script for generating
custom-elements.json for tooling.