跳转到内容

安装

配置 npm 源

业务项目需要先确保 .npmrc 能从内部 npm 仓库解析 @freenotes scope:

ini
@freenotes:registry=https://packages.aliyun.com/6339bf7067fa83af64bcb835/npm/freenote-npm/

安装包

bash
pnpm add @freenotes/web-runtime

包内同时提供 ESM、CommonJS 和 TypeScript 声明文件。

ts
import { createStorage } from '@freenotes/web-runtime';

export const storage = createStorage('local');

公开入口

业务方优先从根入口使用稳定 API:

ts
import {
  createBridge,
  createClipboard,
  createDb,
  createHttp,
  createStorage,
  type ClipboardClient,
  type Db,
  type DbDatabase,
  type DbDefinition,
  type StorageArea,
  type StorageGetOptions,
  type StorageSetOptions
} from '@freenotes/web-runtime';

根入口提供独立、无副作用的 capability factory。业务只调用实际需要的 factory,未使用的模块可以被 bundler tree-shake。需要更严格的物理边界时,也可以使用显式 subpath:

ts
import { createHttp } from '@freenotes/web-runtime/http';
import { createStorage } from '@freenotes/web-runtime/storage';

让基础能力保持简单,让业务开发更加专注。