@deot/docs-launch 1.0.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -9
- package/dist/index.js +25 -49
- package/package.json +1 -1
- package/dist/index.cjs +0 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @deot/docs-launch
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
轻量浏览器启动入口:使用 HTML 选定的 CDN,先注入完整的 Client CSS,再注入 Client module。
|
|
4
4
|
|
|
5
5
|
```html
|
|
6
6
|
<div id="app"></div>
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
window.$docs = {
|
|
9
9
|
locales: { 'zh-CN': { label: '简体中文' } },
|
|
10
10
|
routes: { '/:name': { content: 'default' } },
|
|
11
|
-
//
|
|
12
|
-
|
|
11
|
+
// 可省略,launch 缺省使用 jsDelivr。
|
|
12
|
+
runtime: { mode: 'production', cdn: 'https://cdn.jsdelivr.net/npm/' },
|
|
13
13
|
resolve: {
|
|
14
14
|
cdn: ({ url }) => url
|
|
15
15
|
}
|
|
@@ -18,18 +18,18 @@
|
|
|
18
18
|
<script type="module" src="https://cdn.jsdelivr.net/npm/@deot/docs-launch/+esm"></script>
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
CDN 选择由 HTML 负责。本仓库的 [`index.html`](../../index.html) 并发下载 jsDelivr、ESM UNPKG 的 launch 入口,首个完整下载成功的 JavaScript 响应胜出,随后取消其余请求、将对应 npm CDN 前缀写入 `$docs.runtime.cdn`,并将下载的代码注入为 module。只执行胜出的入口,无需再次下载;全部失败或超过 15 秒时显示刷新重试提示。launch 是自包含 ESM,无需额外探针、节点缓存或 `cdns` 配置。
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
launch 读取 `$docs.runtime.cdn`,缺省使用 `https://cdn.jsdelivr.net/npm/`,补全 production 运行模式;同一页面重复启动复用同一任务。启动器先插入 Client stylesheet link,再插入 Client module script,不等待 CSS load 事件才请求 JS。Client 浏览器 CSS 已包含主应用使用的 Renderer、Markdown、Playground 和延迟页面样式,无需再加载三个子包的 CSS。
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
两个 CDN 都显式加载 `/@deot/docs-client/dist/bundle/index.js` 和 `/@deot/docs-client/dist/bundle/index.style.css`。Bundle 由 `--bundle-package client` 生成,普通 ES 继续供项目打包器使用。所有地址先按选中节点生成,再经过用户可选的同步 `resolve.cdn({ url })`。返回 `null`、`undefined` 或空字符串时保留原地址,钩子本身不会被启动器替换。
|
|
26
26
|
|
|
27
27
|
Client 与 Playground 内置 jsDelivr / UNPKG 地址转换,继续使用选中的同一节点,再调用用户钩子。原配置与缓存保留原始地址。转换服务内部模块引用及重定向仍交给浏览器处理。
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
任一 Client 启动资源加载失败,或 CSS、JS 两份资源在 30 秒内未全部加载完成时,输出控制台错误,并在尚未挂载的 `#app` 中显示刷新重试提示。launch 不切换 CDN 或自动重载页面。
|
|
30
30
|
|
|
31
31
|
包没有运行时依赖,通过 `--minify-package 'launch'` 生成单个自包含的普通压缩 ESM,体积预算为 3 KiB、gzip 后 1.5 KiB。无需 eval 或解压器。聚合包不会重导出自动启动入口。
|
|
32
32
|
|
|
33
|
-
本仓库 `doc dev`
|
|
33
|
+
本仓库 `doc dev` 确认 Client 包名、源码入口及真实路径边界后,将 HTML 的 launch 地址改写到本地 Client 源码,交给 Vite 编译;`doc preview` 映射预先构建的本地 launch 和 Client Bundle,先执行 `npm run build`,预览适配会先调用用户钩子,再映射本地 Client URL。消费项目仍使用声明的发布地址。
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
发布顺序:先发布包含完整 CSS 的 Client,确认两个 CDN 均能提供新产物,再发布读取 `runtime.cdn` 的 launch,最后更新 HTML 入口、开发服务与聚合包。
|
package/dist/index.js
CHANGED
|
@@ -1,54 +1,30 @@
|
|
|
1
1
|
//#region packages/launch/src/index.ts
|
|
2
|
-
var e =
|
|
3
|
-
let
|
|
4
|
-
return
|
|
5
|
-
let
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
try {
|
|
11
|
-
let e = await fetch(`${t}@deot/docs-theme@1.1.4/package.json?raw`, { signal: r.signal });
|
|
12
|
-
if (!e.ok) throw Error(`${e.status} ${t}`);
|
|
13
|
-
return await e.text(), t;
|
|
14
|
-
} finally {
|
|
15
|
-
clearTimeout(i);
|
|
16
|
-
}
|
|
17
|
-
}));
|
|
18
|
-
} finally {
|
|
19
|
-
e.forEach((e) => e.abort());
|
|
20
|
-
}
|
|
21
|
-
})().then((e) => {
|
|
22
|
-
try {
|
|
23
|
-
i.localStorage.setItem(n, e);
|
|
24
|
-
} catch {}
|
|
25
|
-
return e;
|
|
26
|
-
}), s = "";
|
|
27
|
-
try {
|
|
28
|
-
s = i.localStorage.getItem(n) || "";
|
|
29
|
-
} catch {}
|
|
30
|
-
a.includes(s) ? o.catch(() => {}) : s = await o, t.runtime = {
|
|
31
|
-
...t.runtime,
|
|
32
|
-
mode: t.runtime?.mode || "production",
|
|
33
|
-
cdn: s
|
|
2
|
+
var e = Symbol.for("@deot/docs-launch"), t = (t = window) => {
|
|
3
|
+
let n = t;
|
|
4
|
+
return n[e] ??= (async () => {
|
|
5
|
+
let e = n.$docs ||= {}, t = `${(e.runtime?.cdn?.trim() || "https://cdn.jsdelivr.net/npm/").replace(/\/+$/u, "")}/`;
|
|
6
|
+
e.runtime = {
|
|
7
|
+
...e.runtime,
|
|
8
|
+
mode: e.runtime?.mode || "production",
|
|
9
|
+
cdn: t
|
|
34
10
|
};
|
|
35
|
-
let
|
|
36
|
-
let
|
|
37
|
-
return
|
|
38
|
-
},
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
-
let
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
let
|
|
49
|
-
|
|
11
|
+
let r = (n) => {
|
|
12
|
+
let r = `${t}${n}`;
|
|
13
|
+
return e.resolve?.cdn?.({ url: r }) || r;
|
|
14
|
+
}, i = n.document, a = i.createElement("link");
|
|
15
|
+
a.rel = "stylesheet", a.href = r("@deot/docs-client/dist/bundle/index.style.css");
|
|
16
|
+
let o = i.createElement("script");
|
|
17
|
+
o.type = "module", o.src = r("@deot/docs-client/dist/bundle/index.js");
|
|
18
|
+
let s = [a, o], c = s.length, l = !1, u = setTimeout(() => d(), 3e4), d = (e) => {
|
|
19
|
+
if (l || e?.type === "load" && --c || (l = !0, clearTimeout(u), e?.type === "load")) return;
|
|
20
|
+
console.error("[docs-launch] Failed to load", t, e);
|
|
21
|
+
let n = i.querySelector("#app:not([data-v-app])");
|
|
22
|
+
n && (n.textContent = "文档资源加载失败,请刷新重试。");
|
|
23
|
+
};
|
|
24
|
+
for (let e of s) e.addEventListener("load", d), e.addEventListener("error", d);
|
|
25
|
+
i.head.appendChild(a), i.body.appendChild(o);
|
|
50
26
|
})();
|
|
51
27
|
};
|
|
52
|
-
typeof window < "u" && document.querySelector("#app") &&
|
|
28
|
+
typeof window < "u" && document.querySelector("#app") && t().catch((e) => console.error("[docs-launch] Failed to launch", e));
|
|
53
29
|
//#endregion
|
|
54
|
-
export {
|
|
30
|
+
export { t as launch };
|
package/package.json
CHANGED
package/dist/index.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=[`https://cdn.jsdelivr.net/npm/`,`https://esm.unpkg.com/`],t=Symbol.for(`@deot/docs-launch`),n=`@deot/docs-launch:cdn`,r=(r=window)=>{let i=r;return i[t]??=(async()=>{let t=i.$docs||={},r=t.cdns?.map(e=>e.trim()).filter(Boolean),a=[...new Set((r?.length?r:e).map(e=>`${e.replace(/\/+$/u,``)}/`))],o=(async()=>{let e=a.map(()=>new AbortController);try{return await Promise.any(a.map(async(t,n)=>{let r=e[n],i=setTimeout(()=>r.abort(),5e3);try{let e=await fetch(`${t}@deot/docs-theme@1.1.4/package.json?raw`,{signal:r.signal});if(!e.ok)throw Error(`${e.status} ${t}`);return await e.text(),t}finally{clearTimeout(i)}}))}finally{e.forEach(e=>e.abort())}})().then(e=>{try{i.localStorage.setItem(n,e)}catch{}return e}),s=``;try{s=i.localStorage.getItem(n)||``}catch{}a.includes(s)?o.catch(()=>{}):s=await o,t.runtime={...t.runtime,mode:t.runtime?.mode||`production`,cdn:s};let c=e=>{let n=`${s}${e}`;return t.resolve?.cdn?.({url:n})||n},l=i.document;for(let e of[`client`,`renderer`,`markdown`,`playground`]){let t=l.createElement(`link`);t.rel=`stylesheet`,t.href=c(`@deot/docs-${e}/dist/index.style.css`),t.onerror=()=>console.error(`[docs-launch] Failed to load ${t.href}`),l.head.appendChild(t)}let u=l.createElement(`script`);u.type=`module`,u.src=c(`@deot/docs-client${new URL(s).hostname===`esm.unpkg.com`?``:`/+esm`}`),u.onerror=()=>console.error(`[docs-launch] Failed to load ${u.src}`),l.body.appendChild(u)})()};typeof window<`u`&&document.querySelector(`#app`)&&r().catch(e=>console.error(`[docs-launch] Failed to launch`,e)),exports.launch=r;
|