Lit

Lit 是一个用于构建快速、轻量级 web 组件的简单库。(Lit is a simple library for building fast, lightweight web components.)

Github星跟踪图

lit-html

高效、有表现力、可扩展的 JavaScript HTML 模板。

文献资料

完整的文档可在 lit-html.polymer-project.org 中找到。

文件源代码位于 docs 资料夹中。 要自己构建网站,请参阅 docs/README.md 中的说明。

总览

lit-html 允许您使用 JavaScript 编写带有template literals(模板文本)HTML 模板

lit-html 模板是纯 JavaScript,将编写 HTML 的熟悉程度与 JavaScript 的功能结合在一起。 lit-html 负责有效地将模板呈现给 DOM,包括使用新值有效地更新 DOM。

import {html, render} from 'lit-html';
// This is a lit-html template function. It returns a lit-html template.
const helloTemplate = (name) => html`<div>Hello ${name}!</div>`;
// This renders <div>Hello Steve!</div> to the document body
render(helloTemplate('Steve'), document.body);
// This updates to <div>Hello Kevin!</div>, but only updates the ${name} part
render(helloTemplate('Kevin'), document.body);

lit-html 提供了两个主要 Exports:

  • html: 一个 JavaScript template tag(模板标记), 用于产生 TemplateResult,这是模板的容器,以及应填充模板的值。
  • render(): 将TemplateResult渲染到DOM容器(例如元素或影子根)的函数。

贡献

请参阅 CONTRIBUTING.md

主要指标

概览
名称与所有者lit/lit
主编程语言TypeScript
编程语言TypeScript (语言数: 6)
平台Cross-platform, Web browsers
许可证BSD 3-Clause "New" or "Revised" License
所有者活动
创建于2017-06-29 16:27:16
推送于2025-06-24 01:15:33
最后一次提交
发布数557
最新版本名称@lit-labs/nextjs@0.2.3 (发布于 2025-04-11 15:37:19)
第一版名称0.6.0 (发布于 )
用户参与
星数19.9k
关注者数211
派生数1k
提交数2.6k
已启用问题?
问题数1969
打开的问题数429
拉请求数1824
打开的拉请求数150
关闭的拉请求数536
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?

Simple. Fast. Web Components.

Build Status
Published on npm
Join our Discord
Mentioned in Awesome Lit

Lit is a simple library for building fast, lightweight web components.

At Lit's core is a boilerplate-killing component base class that provides reactive state, scoped styles, and a declarative template system that's tiny, fast and expressive.

Documentation

See the full documentation for Lit at lit.dev.

Additional documentation for developers looking to contribute or understand more about the project can be found in dev-docs.

npm

To install from npm:

npm i lit

Lit Monorepo

This is the monorepo for Lit packages.

lit 2.x source is available on the 2.x branch.
lit-html 1.x source is available on the lit-html-1.x branch.

Packages

Contributing to Lit

Lit is open source and we appreciate issue reports and pull requests. See CONTRIBUTING.md for more information.

Setting up the lit monorepo for development

Initialize repo:

git clone https://github.com/lit/lit.git
cd lit
npm ci

Build all packages:

npm run build

Test all packages:

npm run test

Run benchmarks for all packages:

npm run benchmarks

See individual package READMEs for details on developing for a specific package.