@uniweb/runtime

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

Minimal runtime for loading Uniweb foundations

原始使用文档
文档目录11 节
  1. Overview
  2. Installation
  3. Usage
  4. Runtime Loading
  5. Static Bundling
  6. API
  7. initRuntime(source, options)
  8. Architecture
  9. Build Plugins
  10. Related Packages
  11. License

@uniweb/runtime

Minimal runtime for loading Uniweb foundations and orchestrating rendering.

Overview

This package provides the browser-side runtime for Uniweb sites. It loads foundations dynamically and renders content using React Router.

For Vite build plugins, see @uniweb/build.

Installation

npm install @uniweb/runtime

Usage

Runtime Loading

Initialize the runtime with a 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'
})

Static Bundling

Foundation imported directly and bundled with the site:

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

initRuntime(Foundation)

API

initRuntime(source, options)

Initialize the runtime with a foundation.

source - One of:

  • URL string to foundation module
  • Object with { url, cssUrl }
  • Foundation module object (for static bundling)

options:

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

For core classes (Uniweb, Website, Block, etc.), import from @uniweb/core.

Architecture

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

Foundations should:

  • Import components from @uniweb/kit (bundled)
  • Mark @uniweb/core as external (provided by runtime)

Build Plugins

Vite plugins have moved to @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' }),
  ]
})

License

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