@uniweb/runtime

中文文档
1.3.12发布于 2026/11/03Apache-2.0ES Module

加载Uniweb基础的最小运行时

中文使用文档
文档目录11 节
  1. 概述
  2. 安装
  3. 使用
  4. 运行时加载
  5. 静态绑定
  6. API
  7. initRuntime(来源、期权)
  8. 体系结构
  9. 构建插件
  10. 相关的包
  11. 许可证

@uniweb /运行时

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

概述

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

有关Vite构建插件,请参见 @uniweb/build.

安装

npm install @uniweb/runtime

使用

运行时加载

使用Foundation URL初始化运行时:

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'
})

静态绑定

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

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

initRuntime(Foundation)

API

initRuntime(来源、期权)

使用基础初始化运行时。

源 -其中之一:

  • 基础模块的URL字符串
  • 对象与 { url, cssUrl }
  • 基础模块对象(用于静态捆绑)

选项:

{
  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.

体系结构

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

基础:

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

构建插件

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

// 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' }),
  ]
})

许可证

Apache 2.0

版本与发布记录

@uniweb/runtime 共发布 297 个版本,首次发布于 2026/01/15;过去 12 个月发布了 297 个版本。

版本发布日期距今
1.3.12latest2026/11/03今天
1.3.112026/11/021 天前
1.3.102026/11/021 天前
1.3.92026/11/021 天前
1.3.82026/11/021 天前
1.3.72026/11/012 天前

关于 @uniweb/runtime 的常见问题

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