.cursor/skills/bk-weweb/SKILL.md
蓝鲸 BK-WeWeb 微前端框架使用指南。帮助用户使用 bk-weweb 实现微应用和微模块的加载、隔离和通信。当用户询问微前端、bk-weweb、子应用加载、JS沙箱、CSS隔离、预加载或需要创建微前端应用时使用此 skill。
npx skillsauth add TencentBlueKing/bk-weweb bk-wewebInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
BK-WeWeb 是腾讯蓝鲸团队开源的轻量级微前端框架,基于 Web Components 技术,支持微应用和微模块两种模式。
npm install @blueking/bk-weweb
// main.ts
import '@blueking/bk-weweb';
| 模式 | 说明 | 入口类型 | 适用场景 | | ---------------- | ---------------- | -------- | ------------------ | | 微应用 (app) | 加载完整远程应用 | HTML | 独立部署的完整应用 | | 微模块 (js) | 加载远程 JS 模块 | JS | 远程组件、插件系统 |
<template>
<!-- 微应用 -->
<bk-weweb
id="child-app"
url="http://localhost:8001/"
:scope-js="true"
:scope-css="true"
/>
<!-- 微模块 -->
<bk-weweb
id="chart-module"
mode="js"
url="http://localhost:8002/widget.js"
/>
</template>
import { loadApp, mount, unmount } from '@blueking/bk-weweb';
// 加载并挂载微应用
await loadApp({
url: 'http://localhost:8001/',
id: 'my-app',
scopeJs: true,
scopeCss: true,
data: { userId: '123', token: 'xxx' },
});
mount('my-app', document.getElementById('container'));
// 卸载
unmount('my-app');
| API | 说明 |
| ----------------------------------------- | ---------------------------------------------- |
| loadApp(props) | 加载微应用,返回 Promise<MicroAppModel> |
| loadInstance(props) | 加载微模块,返回 Promise<MicroInstanceModel> |
| mount(appKey, container?, callback?) | 挂载到容器 |
| unmount(appKey) | 卸载应用/模块 |
| activated(appKey, container, callback?) | 激活(用于 keepAlive 模式) |
| deactivated(appKey) | 停用(用于 keepAlive 模式) |
| unload(url) | 删除缓存 |
| API | 说明 |
| --------------------------- | -------------- |
| preLoadApp(options) | 预加载微应用 |
| preLoadInstance(options) | 预加载微模块 |
| preLoadSource(sourceList) | 预加载资源文件 |
import weWeb from '@blueking/bk-weweb';
weWeb.start({
collectBaseSource: true, // 收集主应用资源供子应用共享
webComponentTag: 'my-micro-app', // 自定义标签名
fetchSource: async (url, options) => {
// 自定义资源获取(如添加认证头)
const response = await fetch(url, {
...options,
headers: { Authorization: `Bearer ${token}` },
});
return response.text();
},
});
| 属性 | 类型 | 默认值 | 说明 |
| ---------------- | --------------- | ------- | ---------------------- |
| url | string | - | 必填,应用入口 URL |
| id | string | - | 应用唯一标识符 |
| scopeJs | boolean | true | JS 沙箱隔离 |
| scopeCss | boolean | true | CSS 样式隔离 |
| scopeLocation | boolean | false | 路由隔离 |
| setShadowDom | boolean | false | 使用 Shadow DOM |
| keepAlive | boolean | false | 缓存模式 |
| showSourceCode | boolean | false | 显示源码 |
| data | object/string | - | 传递数据 |
| initSource | string[] | - | 初始化资源 |
| 属性 | 类型 | 默认值 | 说明 |
| ---------------- | --------------- | ------- | ---------------------- |
| url | string | - | 必填,JS 模块 URL |
| id | string | - | 必填,模块唯一标识 |
| mode | 'js' | - | 必填,设为 'js' |
| scopeJs | boolean | false | JS 沙箱隔离 |
| scopeCss | boolean | true | CSS 样式隔离 |
| keepAlive | boolean | false | 缓存模式 |
| showSourceCode | boolean | true | 显示源码 |
| data | object/string | - | 传递数据 |
子应用中可通过以下全局变量获取运行时信息:
if (window.__POWERED_BY_BK_WEWEB__) {
const appKey = window.__BK_WEWEB_APP_KEY__; // 应用标识
const data = window.__BK_WEWEB_DATA__; // 主应用传递的数据
const realWindow = window.rawWindow; // 原始 window
const realDocument = window.rawDocument; // 原始 document
}
微模块需导出包含 render 方法的对象:
// widget.js
export default {
render(container: HTMLElement, data: Record<string, unknown>) {
container.innerHTML = `<div>Hello ${data.name}</div>`;
// 返回销毁函数
return () => {
container.innerHTML = '';
};
},
// 可选:其他方法供主应用调用
update(newData) {
/* ... */
},
getState() {
return {
/* ... */
};
},
};
<script setup lang="ts">
import { ref, onMounted, onBeforeUnmount } from 'vue';
import { loadApp, mount, unmount } from '@blueking/bk-weweb';
const containerRef = ref<HTMLElement>();
const appId = 'child-app';
onMounted(async () => {
await loadApp({
url: 'http://localhost:8001/',
id: appId,
scopeJs: true,
scopeCss: true,
data: { userId: '123' },
});
mount(appId, containerRef.value!);
});
onBeforeUnmount(() => unmount(appId));
</script>
<template>
<div
ref="containerRef"
class="app-container"
></div>
</template>
import { useRef, useEffect } from 'react';
import { loadApp, mount, unmount } from '@blueking/bk-weweb';
const MicroApp: React.FC = () => {
const containerRef = useRef<HTMLDivElement>(null);
const appId = 'child-app';
useEffect(() => {
const load = async () => {
await loadApp({
url: 'http://localhost:8001/',
id: appId,
scopeJs: true,
scopeCss: true,
});
if (containerRef.current) {
mount(appId, containerRef.current);
}
};
load();
return () => unmount(appId);
}, []);
return (
<div
ref={containerRef}
style={{ height: '600px' }}
/>
);
};
import { preLoadApp, mount } from '@blueking/bk-weweb';
// 页面加载完成后预加载
window.addEventListener('load', () => {
setTimeout(() => {
preLoadApp({
url: 'http://localhost:8001/',
id: 'dashboard',
scopeJs: true,
});
}, 2000); // 延迟避免影响首屏
});
// 需要时直接挂载(无需等待加载)
function showDashboard() {
mount('dashboard', document.getElementById('container'));
}
scopeCss 已开启setShadowDom 获得更彻底隔离!importantscopeLocation 实现路由隔离// 子应用中访问真实 window
const realWindow = window.rawWindow || window;
const mainConfig = realWindow.__MAIN_APP_CONFIG__;
import {
loadApp,
loadInstance,
mount,
unmount,
activated,
deactivated,
unload,
preLoadApp,
preLoadInstance,
preLoadSource,
WewebMode,
type IAppModelProps,
type IJsModelProps,
type BaseModel,
} from '@blueking/bk-weweb';
development
Maintainer-only workflow for handling GitHub Secret Scanning alerts on OpenClaw. Use when Codex needs to triage, redact, clean up, and resolve secret leakage found in issue comments, issue bodies, PR comments, or other GitHub content.
development
Maintainer workflow for OpenClaw releases, prereleases, changelog release notes, and publish validation. Use when Codex needs to prepare or verify stable or beta release steps, align version naming, assemble release notes, check release auth requirements, or validate publish-time commands and artifacts.
development
Run, watch, debug, and extend OpenClaw QA testing with qa-lab and qa-channel. Use when Codex needs to execute the repo-backed QA suite, inspect live QA artifacts, debug failing scenarios, add new QA scenarios, or explain the OpenClaw QA workflow. Prefer the live OpenAI lane with regular openai/gpt-5.4 in fast mode; do not use gpt-5.4-pro or gpt-5.4-mini unless the user explicitly overrides that policy.
development
End-to-end Parallels smoke, upgrade, and rerun workflow for OpenClaw across macOS, Windows, and Linux guests. Use when Codex needs to run, rerun, debug, or interpret VM-based install, onboarding, gateway smoke tests, latest-release-to-main upgrade checks, fresh snapshot retests, or optional Discord roundtrip verification under Parallels.