@element-hq/element-web-module-api

中文文档
2.5.0发布于 2026/11/12SEE LICENSE IN README.mdTypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 1.2万

Module API surface for element-web

原始使用文档
文档目录4 节
  1. Using the API
  2. Accessing application configuration
  3. Releases
  4. Copyright & License

@element-hq/element-web-module-api

API surface for extending Element Web in a safe & predictable way.

Using the API

Modules are loaded by Element Web at runtime via a dynamic ecmascript import, but can be bundled into a webapp for deployment convenience.

The module's default export MUST be a class which accepts a single argument, an instance of ModuleApi. This class must also bear a static property moduleApiVersion which is a semver range string and a load method which is called when the module is to be loaded.

import type { Module, Api, ModuleFactory } from "@element-hq/element-web-module-api";

class ExampleModule implements Module {
    public static readonly moduleApiVersion = "^2.0.0";

    public constructor(private api: Api) {}

    public async load(): Promise<void> {
        // Your extension code goes here
    }
}

export default ExampleModule satisfies ModuleFactory;

Accessing application configuration

The api object passed to the module constructor provides access to the application configuration. You can extend the Config types using declaration merging, though please ensure that you do not trust the types you specify, and opt for runtime validation due to the dynamic nature of the configuration.

// ...
declare module "@element-hq/element-web-module-api" {
    interface Config {
        "this.is.my.config.key": string;
    }
}

class ExampleModule implements Module {
    // ...
    public async load(): Promise<void> {
        const configValue = this.api.config.get("this.is.my.config.key");
        // Your extension code goes here
    }
}
// ...

Releases

The API is versioned using semver, with the major version incremented for breaking changes.

To carry out a release, see the documentation at ../RELEASING.md.

Copyright (c) 2025 New Vector Ltd

This software is multi licensed by New Vector Ltd (Element). It can be used either:

(1) for free under the terms of the GNU Affero General Public License (as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version); OR

(2) under the terms of a paid-for Element Commercial License agreement between you and Element (the terms of which may vary depending on what you and Element have agreed to). Unless required by applicable law or agreed to in writing, software distributed under the Licenses is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Licenses for the specific language governing permissions and limitations under the Licenses.

版本与发布记录

@element-hq/element-web-module-api 共发布 28 个版本,首次发布于 2025/01/30;过去 12 个月发布了 19 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.5.0latest2026/11/121 天前
2.4.02026/11/067 天前
2.3.02026/10/1529 天前
2.2.02026/09/231 个月前
2.1.02026/09/171 个月前
2.0.02026/09/151 个月前

关于 @element-hq/element-web-module-api 的常见问题

@element-hq/element-web-module-api 是什么?

Module API surface for element-web

如何安装 @element-hq/element-web-module-api?

在项目目录运行 npm install @element-hq/element-web-module-api,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^19)、@types/react(*)、@types/react-dom(*)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@element-hq/element-web-module-api 支持 TypeScript 吗?

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

@element-hq/element-web-module-api 支持 ESM 还是 CommonJS?

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

@element-hq/element-web-module-api 需要什么版本的 Node.js?

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

@element-hq/element-web-module-api 可以商用吗?

@element-hq/element-web-module-api 使用 SEE LICENSE IN README.md 许可。许可条款写在包内的独立文件中,请阅读该文件确认可否商用。以上为概括,不构成法律意见,请以许可原文为准。

@element-hq/element-web-module-api 的下载量有多少?

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

@element-hq/element-web-module-api 还在维护吗?

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