@funcd-dev/vite-plugin

中文文档
0.29.0发布于 2026/11/14Apache-2.0TypeScriptES Module零依赖构建来源已验证近 30 天下载 2639

Vite plugin that bundles each funcd function into one self-contained ES module

原始使用文档

@funcd-dev/vite-plugin

A Vite plugin that bundles each funcd function into one self-contained ES module for the funcd Node runtime (funcd ADR-0144), and puts its contract file beside it (funcd ADR-0247).

yarn add -D vite @funcd-dev/vite-plugin
// vite.config.ts
import { funcd } from '@funcd-dev/vite-plugin';
import { defineConfig } from 'vite';

export default defineConfig({
  plugins: [funcd({ functions: { front: 'src/front/main.ts', greeter: 'src/greeter/main.ts' } })],
});

vite build builds each function as its own Vite environment, so no code is split into a shared chunk:

  • dist/<name>.mjs: the handler with its dependencies inlined, ESM for Node 22, Node builtins left external, not minified.
  • dist/<name>.contract.yaml (or .json): the function's contract file, copied from <name>.contract.yaml or <name>.contract.json at the project root. A function with neither, or with both, fails the build.

Then funcdctl push dist/<name>.mjs <ref> takes the runtime and the contract from the contract file beside the file. The Function's bindings and stores live in its resource file, not here.

funcdctl.yaml is read nowhere: a project that still has funcdctl.yaml or <name>.funcdctl.yaml fails the build, naming the contract file that replaces it.

OptionDefaultWhat
functions{ <root dir name>: 'src/main.ts' }function name → handler source, relative to the Vite root
outDir'dist'where <name>.mjs goes; the project root ('.') works too, and then the contract file is not copied

Each function builds into a staging directory under Vite's cache directory, and the plugin copies the result into outDir, so a shared output directory is never emptied.

Watch mode

vite build --watch keeps outDir current, one function at a time (funcd ADR-0244):

  • When a function's rebuild ends, its <name>.mjs and contract file are written to outDir; the other functions' files are not touched. Each file is written beside its target and renamed over it, so a reader never sees half a file.
  • Saving a function's contract file rebuilds that function only. A contract file created while the watch runs takes effect at that function's next rebuild.
  • A failed rebuild prints the error and keeps the function's last good files; the watch goes on.

Beside it, funcdctl dev reloads each function whose files change, so a saved handler answers with its new code within about a second:

vite build --watch    # terminal 1
funcdctl dev dist     # terminal 2

A plain vite build still writes outDir only after every function has built, and writes nothing when one fails.

版本与发布记录

@funcd-dev/vite-plugin 共发布 35 个版本,首次发布于 2026/10/02;过去 12 个月发布了 35 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.29.0latest2026/11/141 天前
0.28.02026/11/142 天前
0.27.02026/11/132 天前
0.26.02026/11/132 天前
0.25.02026/11/105 天前
0.24.02026/10/3115 天前

其他发布通道:bootstrap → 0.0.0-bootstrap.0。

关于 @funcd-dev/vite-plugin 的常见问题

@funcd-dev/vite-plugin 是什么?

Vite plugin that bundles each funcd function into one self-contained ES module

如何安装 @funcd-dev/vite-plugin?

在项目目录运行 npm install @funcd-dev/vite-plugin,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:vite(^8.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@funcd-dev/vite-plugin 支持 TypeScript 吗?

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

@funcd-dev/vite-plugin 支持 ESM 还是 CommonJS?

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

@funcd-dev/vite-plugin 需要什么版本的 Node.js?

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

@funcd-dev/vite-plugin 可以商用吗?

@funcd-dev/vite-plugin 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@funcd-dev/vite-plugin 的下载量有多少?

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

@funcd-dev/vite-plugin 还在维护吗?

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