入口配置
功能
app.entry 决定窗口启动后加载什么页面。它的含义由
app.mode 决定。
static 模式
static 模式加载项目内 HTML 文件:
{
"app": {
"mode": "static",
"entry": "index.html"
}
}
相对路径以项目根目录为基准。运行时会转换为:
bt://app/index.html
路径必须是项目内相对路径,不能是绝对路径,不能包含
..。入口资源不存在时,窗口会显示启动错误页,提示
入口资源不存在。
server 模式
server 模式固定执行项目根目录的
server.bt,窗口加载
app.entry 指定的 HTTP 地址:
{
"app": {
"mode": "server",
"entry": "http://127.0.0.1:18280"
}
}
server.bt 中需要自己启动 Web 服务,并保证监听地址和
app.entry 一致。当前推荐使用
net.listen({ type:'web' })。
remote 模式
remote 模式直接加载远程 Web 地址:
{
"app": {
"mode": "remote",
"entry": "https://example.com"
}
}
remote 模式的
entry 必须以
http:// 或
https:// 开头。
默认值
| 模式 | entry 默认值 |
|---|
static | index.html |
server | http://127.0.0.1:18280 |
remote | https://example.com |
bt:// 地址
开发者通常不需要在
app.entry 中手写
bt://。
static 模式会自动把相对入口转换为
bt://app/...。
页面内部可以引用:
<script src="bt://app/main.js"></script>
<link rel="stylesheet" href="bt://app/style.css">
排查
- 本地入口打不开:检查
app.mode 是否为 static,entry 文件是否存在,路径是否没有 ..。
- 本地服务打不开:检查
server.bt 是否存在,端口是否被占用,net.listen 监听地址是否和 app.entry 一致。
- 远程入口打不开:检查网络、证书、URL 是否能在普通浏览器打开。
- 入口路径不能访问项目外文件;开发目录和 Bundle 都会校验安全相对路径。