OpenClaw 纯 Windows 环境源码部署教程(含修改脚本配置)

OpenClaw 纯 Windows 环境源码编译部署教程(含修改脚本配置)

本文专为 Windows 10/11 系统编写(理论上是跨平台 any os),全程实操无冗余,涵盖 OpenClaw 源码克隆、环境搭建、关键脚本修改、依赖构建及项目启动,重点解决 A2UI 打包相关配置,适合新手快速上手部署。

一、前置环境准备(自行安装配置)

所有工具均需配置系统环境变量(安装时勾选"Add to PATH",或手动配置),确保命令可全局调用。

  1. Node.js :推荐 v20+ 版本

    下载地址:https://nodejs.org/(选择 Windows Installer 64-bit)

  2. pnpm :安装 Node.js 后,打开 CMD/PowerShell 执行
    npm install -g pnpm

  3. Git :用于克隆项目源码

    下载地址:https://git-scm.com/download/win

  4. Python 3.10+ :编译项目依赖需用到

    下载地址:https://www.python.org/(安装时勾选"Add Python to PATH")

二、克隆 OpenClaw 源码

打开 CMD/PowerShell,执行以下命令,克隆项目到本地(可自定义路径):

bash 复制代码
# 克隆项目
git clone https://github.com/openclaw/openclaw.git

# 或者使用我已经fork的 OpenClaw 仓库地址
git clone https://github.com/WJX20/openclaw.git

# 进入项目根目录
cd OpenClaw

三、关键配置:修改 A2UI 打包脚本(核心步骤)

这一步是部署成功的关键,需修改 package.json 命令,并新建指定脚本文件。

1. 修改 package.json 命令

打开项目根目录的 package.json 文件,搜索并找到 "canvas:a2ui:bundle" 字段,将其替换为以下内容:

json 复制代码
"canvas:a2ui:bundle": "node --import tsx scripts/bundle-a2ui.mts",

2. 新建 bundle-a2ui.mts 脚本

在项目根目录的 scripts 文件夹下(若没有则新建 scripts 文件夹),新建文件 bundle-a2ui.mts,复制以下完整代码粘贴进去(直接复制可用,无需修改):

typescript 复制代码
import { createHash } from "node:crypto";
import { promises as fs } from "node:fs";
import path from "node:path";
import { execSync } from "node:child_process";
import { fileURLToPath } from "node:url";

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const ROOT_DIR = path.resolve(__dirname, "..");
const HASH_FILE = path.join(ROOT_DIR, "src/canvas-host/a2ui/.bundle.hash");
const OUTPUT_FILE = path.join(ROOT_DIR, "src/canvas-host/a2ui/a2ui.bundle.js");
const A2UI_RENDERER_DIR = path.join(ROOT_DIR, "vendor/a2ui/renderers/lit");
const A2UI_APP_DIR = path.join(ROOT_DIR, "apps/shared/OpenClawKit/Tools/CanvasA2UI");

const exists = async (p: string) => fs.access(p).then(() => true).catch(() => false);

// 检查源码目录
const rendererExists = await exists(A2UI_RENDERER_DIR);
const appExists = await exists(A2UI_APP_DIR);

if (!rendererExists || !appExists) {
  if (await exists(OUTPUT_FILE)) {
    console.log("A2UI sources missing; keeping prebuilt bundle.");
    process.exit(0);
  }
  console.error(`A2UI sources missing and no prebuilt bundle found at: ${OUTPUT_FILE}`);
  process.exit(1);
}

// 计算哈希
async function walk(entryPath: string): Promise<string[]> {
  const st = await fs.stat(entryPath);
  if (st.isDirectory()) {
    const entries = await fs.readdir(entryPath);
    const results = await Promise.all(entries.map(e => walk(path.join(entryPath, e))));
    return results.flat();
  }
  return [entryPath];
}

const normalize = (p: string) => p.split(path.sep).join("/");

const inputPaths = [
  path.join(ROOT_DIR, "package.json"),
  path.join(ROOT_DIR, "pnpm-lock.yaml"),
  A2UI_RENDERER_DIR,
  A2UI_APP_DIR,
];

const allFiles = (await Promise.all(inputPaths.map(walk))).flat();
allFiles.sort((a, b) => normalize(a).localeCompare(normalize(b)));

const hash = createHash("sha256");
for (const filePath of allFiles) {
  const rel = normalize(path.relative(ROOT_DIR, filePath));
  hash.update(rel);
  hash.update("\0");
  hash.update(await fs.readFile(filePath));
  hash.update("\0");
}
const currentHash = hash.digest("hex");

// 检查是否需要重新构建
if (await exists(HASH_FILE) && await exists(OUTPUT_FILE)) {
  const previousHash = (await fs.readFile(HASH_FILE, "utf8")).trim();
  if (previousHash === currentHash) {
    console.log("A2UI bundle up to date; skipping.");
    process.exit(0);
  }
}

const exec = (cmd: string) => execSync(cmd, { stdio: "inherit", cwd: ROOT_DIR });

// 编译 TypeScript
exec(`pnpm -s exec tsc -p "${A2UI_RENDERER_DIR}/tsconfig.json"`);

// 打包
try {
  execSync("rolldown --version", { stdio: "ignore" });
  exec(`rolldown -c "${A2UI_APP_DIR}/rolldown.config.mjs"`);
} catch {
  exec(`pnpm -s dlx rolldown -c "${A2UI_APP_DIR}/rolldown.config.mjs"`);
}

// 保存哈希
await fs.writeFile(HASH_FILE, currentHash, "utf8");
console.log("A2UI bundle complete.");

四、安装项目依赖并启动

在项目根目录(OpenClaw 文件夹)执行命令,安装所有项目依赖:

复制代码
pnpm install
pnpm ui:build
pnpm build

pnpm link --global

openclaw --version

openclaw onboard --install-daemon

openclaw gateway restart
相关推荐
过期的秋刀鱼!5 分钟前
项目实战-神经网络预测
人工智能·神经网络·机器学习
AI新角度15 分钟前
Cursor Composer 模式:多文件重构的工作流与边界
人工智能
神奇霸王龙16 分钟前
GPT-Image-2 角色一致性屠榜:2026 五款图生图模型 IP 漫剧实测
人工智能·gpt·tcp/ip·ai·ai作画·prompt·音视频
深圳市快瞳科技有限公司17 分钟前
宠物行为识别:将日常行为转化为可量化的健康指标
人工智能·算法·计算机视觉·宠物
Bigger20 分钟前
🔥每天最难的问题不是做饭,而是今天到底吃什么——我做了「烟火食间」
前端·人工智能·agent
tokenKe24 分钟前
ego-lite:给 AI Agent 用的最快浏览器 | SSP Github Daily
人工智能·github
网易云信24 分钟前
企业级 IM,不是功能更多,而是场景更对
人工智能·后端
糖果店的幽灵26 分钟前
大模型测评DeepEval快速入门-RAG指标详解
数据库·人工智能·langgraph·大模型测评·deepeval
小码哥哥27 分钟前
如何从架构层面评价国内六大企业AI知识库的技术差异?
人工智能·架构
库拉大叔28 分钟前
写小说谁家强?GPT-5.6、Claude 4.8 Opus、Gemini 3.5文学素养硬核横评
人工智能·gpt·aigc