@beforesemicolon/web-component

中文文档
1.21.1发布于 2026/11/01BSD-3-ClauseTypeScriptESM + CJS近 30 天下载 3110

具有创建本地Web组件能力的增强标记

中文使用文档
文档目录4 节
  1. 动机
  2. 安装
  3. AI和生态系统背景
  4. 社区

网络组件

Static Badge Test npm npm

增强网络组件 API 标记。 。 。 .

动机

  • 原生的Web组件API太强了. 这意味着你需要为最简单的组件写这么多代码.
  • 即使你能够处理好所有的API,你仍然需要处理DOM操纵,并处理你自己的回放.
  • 标记 提供最简单、最强大的诱导系统 在客户端上没有设置.

由于所有这些原因,引入一个简单的API来为您处理所有的事情是完全合理的.

// import everything from Markup as if you are using it directly
import { WebComponent, html } from '@beforesemicolon/web-component'
import stylesheet from './counter-app.css' with { type: 'css' }

interface Props {
    label: string
}

interface State {
    count: number
}

class CounterApp extends WebComponent<Props, State> {
    static observedAttributes = ['label']
    label = '+' // defined props default value
    initialState = {
        // declare initial state
        count: 0,
    }
    stylesheet = stylesheet

    countUp = (e: Event) => {
        e.stopPropagation()
        e.preventDefault()

        this.setState(({ count }) => ({ count: count + 1 }))
        this.dispatch('click')
    }

    render() {
        return html`
            <p>${this.state.count}</p>
            <button type="button" onclick="${this.countUp}">
                ${this.props.label}
            </button>
        `
    }
}

customElements.define('counter-app', CounterApp)

在您的 HTML 中, 您可以简单地正常使用标记 .

<counter-app label="count up"></counter-app>

安装

npm install @beforesemicolon/web-component

在浏览器中

<!-- use the latest version -->
<script src="https://unpkg.com/@beforesemicolon/web-component/dist/client.js"></script>

<!-- use a specific version -->
<script src="https://unpkg.com/@beforesemicolon/[email protected]/dist/client.js"></script>

<!-- link you app script after -->
<script>
    const { WebComponent } = BFS
    const { html, state, effect } = BFS.MARKUP
</script>

AI和生态系统背景

  • llms.txt 是简洁的, 软件包拥有的API和AI工具的生态系统合同.
  • llms-full.txt 包含完整的解析文档和实例.

Web 组件再出口 Markup. 路由器和 Intl 在 Web 组件上构建并可以 在不改变其组成部分模式的情况下合并组成.

社区

版本与发布记录

@beforesemicolon/web-component 共发布 110 个版本,首次发布于 2021/10/18;过去 12 个月发布了 13 个版本。

版本发布日期距今
1.21.1latest2026/11/016 天前
1.21.2-nextnext2026/10/2513 天前
1.21.02026/08/312 个月前
1.21.1-next2026/08/252 个月前
1.21.0-next2026/08/222 个月前
1.20.12026/08/212 个月前

关于 @beforesemicolon/web-component 的常见问题

@beforesemicolon/web-component 是什么?

具有创建本地Web组件能力的增强标记

如何安装 @beforesemicolon/web-component?

在项目目录运行 npm install @beforesemicolon/web-component,或使用 pnpm add / yarn add / bun add。

@beforesemicolon/web-component 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@beforesemicolon/web-component 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@beforesemicolon/web-component 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.13.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@beforesemicolon/web-component 可以商用吗?

@beforesemicolon/web-component 使用 BSD-3-Clause 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。另外不得用原作者名义为衍生产品背书。以上为概括,不构成法律意见,请以许可原文为准。

@beforesemicolon/web-component 的下载量有多少?

根据 npm 官方下载统计,@beforesemicolon/web-component 在 2026/10/08 – 2026/11/06 这 30 天内被下载 3,110 次,日均约 104 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@beforesemicolon/web-component 还在维护吗?

最新版本 1.21.1 发布于 2026/11/01(6 天前);至今共发布 110 个版本,其中过去 12 个月发布了 13 个;首次发布于 2021/10/18。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。