# @uniweb/runtime 中文文档

规范地址：https://npmcn.com/package/%40uniweb/runtime/

版本：1\.3\.12
npm 元数据更新时间：2026-11-02T16:58:31.206Z
中文译文更新时间：2026-11-02T19:11:06.733Z
软件包许可：Apache-2\.0

本文由上游 README 机器翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40uniweb/runtime
原文对照：https://npmcn.com/package/%40uniweb/runtime/?lang=original
项目主页：https://github.com/uniweb/runtime#readme
源码仓库：https://github.com/uniweb/runtime

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：705 kB，56 个文件
- 模块格式：ES Module
- TypeScript 类型：未声明
- Node.js 要求：\>=22\.12
- 运行依赖：2 个
- peer 依赖：react ^19\.0\.0，react-dom ^19\.0\.0，react-router-dom ^6\.0\.0 \|\| ^7\.0\.0
- 首次发布：2026-01-14T21:08:51.505Z
- 最新版本发布：2026-11-02T16:58:30.324Z
- 已发布版本数：297（近 12 个月 297 个）

## 中文简介

加载Uniweb基础的最小运行时

## 安装

```sh
npm install @uniweb/runtime
```

也可以使用：`pnpm add @uniweb/runtime`、`yarn add @uniweb/runtime`、`bun add @uniweb/runtime`

## README

# @uniweb /运行时

加载Uniweb基础和编排渲染的最小运行时间。

## 概述

这个包为Uniweb站点提供浏览器端运行时。它动态加载基础，并使用React Router渲染内容。

有关Vite构建插件，请参见 [`@uniweb/build`](https://github.com/uniweb/build).

## 安装

```bash
npm install @uniweb/runtime
```

## 使用

### 运行时加载

使用Foundation URL初始化运行时：

```jsx
import initRuntime from '@uniweb/runtime'

// Load foundation from URL
initRuntime('/foundation/foundation.js', {
  development: import.meta.env.DEV,
})

// Or with CSS
initRuntime({
  url: '/foundation/foundation.js',
  cssUrl: '/foundation/assets/style.css'
})
```

### 静态绑定

基金会直接导入并与网站捆绑：

```jsx
import * as Foundation from '@my-org/my-foundation'
import initRuntime from '@uniweb/runtime'

initRuntime(Foundation)
```

## API

### initRuntime(来源、期权)

使用基础初始化运行时。

**源** -其中之一：

-   基础模块的URL字符串
-   对象与 `{ url, cssUrl }`
-   基础模块对象（用于静态捆绑）

**选项:**

```js
{
  development: false,    // Enable dev mode (StrictMode, verbose errors)
  configData: null,      // Site content (or reads from DOM)
  basename: undefined    // React Router basename
}
```

对于核心课程(`Uniweb`， `Website`， `Block`等)，从 [`@uniweb/core`](https://github.com/uniweb/core).

## 体系结构

```
@uniweb/runtime (browser)
    │
    ├── Loads foundation dynamically
    ├── Creates Uniweb instance via @uniweb/core
    └── Orchestrates React/Router rendering
```

基础:

-   从 `@uniweb/kit` (捆绑)
-   马克 `@uniweb/core` 作为外部（由运行时提供）

## 构建插件

Vite插件已经移动到 `@uniweb/build`：

```js
// vite.config.js
import { siteContentPlugin } from '@uniweb/build/site'
import { foundationDevPlugin } from '@uniweb/build/dev'

export default defineConfig({
  plugins: [
    siteContentPlugin({ sitePath: './', inject: true }),
    foundationDevPlugin({ path: '../foundation', serve: '/foundation' }),
  ]
})
```

## 相关的包

-   [`@uniweb/core`](https://github.com/uniweb/core) -核心课程（Uniweb, Website, Block）
-   [`@uniweb/kit`](https://github.com/uniweb/kit) -用于基础的组件库
-   [`@uniweb/build`](https://github.com/uniweb/build) - Vite构建插件
-   [`uniweb`](https://github.com/uniweb/cli) —用于创建项目的CLI

## 许可证

Apache 2.0

## 常见问题

### @uniweb/runtime 是什么？

加载Uniweb基础的最小运行时

### 如何安装 @uniweb/runtime？

在项目目录运行 npm install @uniweb/runtime，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：react（^19\.0\.0）、react-dom（^19\.0\.0）、react-router-dom（^6\.0\.0 \|\| ^7\.0\.0）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @uniweb/runtime 支持 TypeScript 吗？

该包的 package\.json 没有声明类型入口。需要类型提示时，可以在 npm 上查找社区维护的 @types/uniweb\_\_runtime 是否存在。

### @uniweb/runtime 支持 ESM 还是 CommonJS？

以 ES Module 形式发布，推荐使用 import 引入。在 CommonJS 项目中，Node\.js 20\.19\+ / 22\.12\+ 可以直接 require\(\) 不含顶层 await 的 ES Module，更早的版本需要改用动态 import\(\)。

### @uniweb/runtime 需要什么版本的 Node\.js？

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

### @uniweb/runtime 可以商用吗？

@uniweb/runtime 使用 Apache-2\.0 许可。宽松许可：允许商业使用、修改和再分发，并附带明确的专利授权；分发时需保留许可与 NOTICE 文件，修改过的文件要注明改动。以上为概括，不构成法律意见，请以许可原文为准。

### @uniweb/runtime 还在维护吗？

最新版本 1\.3\.12 发布于 2026/11/03（今天）；至今共发布 297 个版本，其中过去 12 个月发布了 297 个；首次发布于 2026/01/15。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

