codex生产openclaw辅助软件打包流程

📅 2026/7/1 16:46:48
codex生产openclaw辅助软件打包流程
## 打包全流程### 项目准备js// 代码中用 __dirname 代替硬编码路径const BASE __dirname;const LOG_FILE path.join(BASE, douyin_reply.log);// ... 其他文件同理### 打包6步**① 装依赖**bashcd 项目目录npm init -ynpm install ws # 以及其他第三方包**② esbuild 打包代码依赖全部内联**bashnpx esbuild engine.js --bundle --platformnode --targetnode22 --formatcjs --outfilebundled.cjs说明--bundle 把所有依赖揉进一个文件--formatcjs 用 CommonJSSEA 兼容。**③ 创建 SEA 配置**项目目录下新建 sea-config.jsonjson{main: bundled.cjs,output: sea-prep.blob,disableExperimentalSEAWarning: true}**④ 生成 blob**bashnode --experimental-sea-config sea-config.json输出sea-prep.blob**⑤ 复制 Node 运行时作为壳**bashcopy D:\node\node.exe 你的程序名.exe⚠️ 必须是用你本机那个 Nodenode -e console.log(process.execPath) 看看路径**⑥ 注入 blob 到 EXE**bashnpx postject 你的程序名.exe NODE_SEA_BLOB sea-prep.blob --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2 --overwrite输出✅ Injection done!### 更新代码后重打包只需重复 **②→④→⑥**不用重新 init/npm install。---## IP 限制可以的。在引擎启动时加一道检查只允许特定 IP 访问管理界面和管理 API。有两个层级### 方案 A管理界面 IP 限制只在 HTTP 服务端加在 startWebServer() 里每个请求前检查来源 IPjsfunction isAllowedIP(req) {const allowed [127.0.0.1, ::1, 192.168.1.100]; // 允许的IP白名单const ip req.socket.remoteAddress.replace(/^::ffff:/, );return allowed.includes(ip);}// 在每个路由处理前加if (!isAllowedIP(req)) {res.writeHead(403, {Content-Type: text/plain});res.end(Forbidden);return;}只能白名单里的 IP 访问管理界面和 API。### 方案 B引擎启动时验证本机 IPjsconst os require(os);const allowedIPs [你指定的IP]; // 打包前写死function checkIP() {const ifaces os.networkInterfaces();for (const name of Object.keys(ifaces)) {for (const iface of ifaces[name]) {if (iface.family IPv4 !iface.internal) {if (!allowedIPs.includes(iface.address)) {console.log(IP not allowed, exiting);process.exit(1); // 非白名单IP直接退出}}}}}checkIP();### 建议- **方案 A 够用了**——管理界面只限本地/内网访问防外网入侵- 如果你想要**绑死这台机器不能拷走用**那就方案 B把本机 IP 写死在代码里打包- 不过 IP 是可以手动改的想要更严的**硬件绑定**比如绑定 MAC 地址或主板序列号也能做但更复杂目前用的这个**Node.js SEASingle Executable Application**是一种**不需要额外二进制下载**的本地打包方式六步走项目代码 → esbuild 内联依赖 → 生成 blob → 注入 Node.exe → 成品 EXE简单说就是把你的代码 ws 这些包全部揉进一个文件然后塞进 Node.exe 里面。双击 EXE 就像平时 node engine.js 一样运行但源码不能直接看了。---至于上次试了没成功的 **yao-pkg/pkg**v6.20.0那个原理类似但更自动化。以后网络好了可以用它替代bashnpm install -g yao-pkg/pkgpkg engine.js -o xxx.exe -t node22-win-x64一步到位不需要手动 cp node postject 注入。但现在网络下不动 GitHub 上的二进制文件所以先用 SEA 方案。