bt_app 快速开始
bt_app 快速开始
纯 HTML 项目
在空目录创建 index.html:
<!doctype html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> </head> <body> <h1>Hello BT App</h1> </body> </html>
在该目录运行:
./bt_app.exe run
首次运行时,如果目录中没有 app.json,bt_app 会自动生成默认 app.json,并在缺少 main.bt 时创建空的 main.bt。窗口标题、尺寸、入口、资源等配置都以 app.json 为准。
也可以直接双击 bt_app.exe,前提是当前工作目录就是项目目录。
app.json 项目
创建 app.json:
{ "app": { "name": "HelloApp", "title": "Hello BT App", "mode": "static", "entry": "index.html", "main": "main.bt" }, "window": { "width": 900, "height": 700, "resizable": true }, "dev": { "watch": true, "delay": 500, "devtools": true, "console": true }, "resources": [ "index.html", "main.bt", "assets/**" ], "exclude": [] }
创建 main.bt:
fn hello(args) { return { error:false, message:'ok', data:'Hello ' + args.name } }
在页面中调用:
<button id="btn">调用 BT</button> <pre id="out"></pre> <script> document.getElementById('btn').onclick = async () => { const result = await window.bt.call('hello', { name: 'BT' }); document.getElementById('out').textContent = JSON.stringify(result, null, 2); }; </script>
打包
在项目目录运行:
./bt_app.exe build
打包结果输出到:
dist/HelloApp.exe
注意事项
-
static模式下entry必须是项目内相对路径。 -
server和remote模式下entry必须是http://或https://地址。 -
app.main省略、true或null时会自动尝试执行main.bt;写成false或空字符串表示不执行主脚本。 - 当前
app.icon只支持项目内.ico文件。 -
index.html不再提供应用配置;需要打包的样式、脚本和图片请写入resources。 - 开发目录运行时,
resources - exclude中的文件保存后会自动刷新页面;也可以按F5、Ctrl+R或Cmd+R手动刷新。