@beforesemicolon/web-component

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

Enhanced Markup with ability to create native Web Components

原始使用文档
文档目录4 节
  1. Motivation
  2. Install
  3. AI and ecosystem context
  4. Community

Web Component

Static Badge Test npm npm

Reactive Web Component API enhanced with Markup.

Motivation

  • Native Web Components APIs are too robust. This means you need to write so much code for the simplest components.
  • Even if you manage to handle all the APIs fine, you still need to deal with DOM manipulation and handle your own reactivity.
  • Markup offers the simplest and more powerful templating system that can be used on the client without setup.

With all these reasons, it only made sense to introduce a simple API to handle everything for you.

// 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)

In your HTML you can simply use the tag normally.

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

Install

npm install @beforesemicolon/web-component

In the browser

<!-- 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 and ecosystem context

  • llms.txt is the concise, package-owned API and ecosystem contract for AI tools.
  • llms-full.txt contains the complete resolved documentation and examples.

Web Component re-exports Markup. Router and Intl build on Web Component and can be composed together without changing its component model.

Community

版本与发布记录

@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 是什么?

Enhanced Markup with ability to create native Web Components

如何安装 @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 和提交记录判断。