Skip to content

参考

基于 developer.stackblitz.com 与 @webcontainer/api 2025–2026 现状编写

URL 速查

操作URL
打开项目stackblitz.com/edit/<id>
fork 项目stackblitz.com/fork/<id>
POST 建项目POST https://stackblitz.com/run
从 GitHub 打开stackblitz.com/github/{owner}/{repo}
GitHub 指定 ref / 子目录stackblitz.com/github/{owner}/{repo}/tree/{ref}/{folder}
从 GitHub fork(分享)stackblitz.com/fork/github/{owner}/{repo}
Codeflow 打开仓库pr.new/github.com/{owner}/{repo}
Codeflow 看 PR diffpr.new/github.com/{owner}/{repo}/pull/{n}

*.new 速建短链(框架自有域名)

短链起出的项目
vite.newVite
vite.new/reactVite + React
astro.newAstro
nextjs.newNext.js
nuxt.newNuxt
node.new空白 Node 项目
sveltekit.newSvelteKit
remix.newRemix
vitepress.newVitePress
sli.dev/newSlidev

这些是各框架自有顶级域名,落地页指向 StackBlitz,不是 stackblitz.com/fork/* 子路径。

SDK 方法签名

方法返回行为
embedProject(elOrId, project, options?)Promise<VM>iframe 替换元素,嵌入内联项目
embedProjectId(elOrId, projectId, options?)Promise<VM>嵌入已存在的项目 ID
embedGithubProject(elOrId, repoSlug, options?)Promise<VM>从 GitHub 嵌入
openProject(project, options?)开新标签(不返回 VM)
openProjectId(projectId, options?)开新标签
openGithubProject(repoSlug, options?)开新标签
connect(iframeEl)Promise<VM>连接已存在的 iframe

repoSlug = "owner/repo",可带 /tree/{branch|tag|commit}/{folder}

VM 方法

成员返回说明
vm.applyFsDiff(diff)Promise<null>{ create: {path:content}, destroy: [] };改文件给全量内容
vm.getFsSnapshot()数据读取文件系统快照
vm.getDependencies()数据读取依赖
vm.editor.openFile(p)Promise<null>打开文件
vm.editor.setCurrentFile(p)Promise<null>切换当前文件
vm.editor.setTheme(t)Promise<null>设主题
vm.editor.setView(v)Promise<null>设视图
vm.editor.showSidebar(b)Promise<null>显隐侧边栏
vm.preview.getUrl()数据读取预览 URL
vm.preview.setUrl(path)Promise<null>设预览路径
vm.preview.origin只读WebContainers 上恒为 null

getFsSnapshot / getDependencies / preview.getUrl 三个 getter 外,VM 方法 resolve 的都是 Promise<null>

嵌入 URL 参数(大小写敏感)

参数取值对应 SDK 选项
embed0 / 1forceEmbedLayout
ctl0 / 1clickToLoad
file路径openFile
vieweditor / previewview
themelight / darktheme
hideNavigation0 / 1
hideExplorer0 / 1hideExplorer
hidedevtools0 / 1(全小写)hideDevTools
devtoolsheight数字(全小写)
terminalHeight0100(camelCase)terminalHeight
showSidebar0 / 1showSidebar
initialpath路径(全小写,URI 编码)
startScriptscript 名startScript
corpcrossOriginIsolated

EmbedOptions / OpenOptions

选项取值 / 默认作用域
clickToLoad默认 false通用
openFile字符串 / 数组通用
view'default' / 'editor' / 'preview'(无 'both')通用
theme'default' / 'dark' / 'light'通用
hideExplorer默认 false通用
hideDevTools默认 false通用
showSidebar布尔通用
sidebarView'project' / 'search' / 'ports' / 'settings'通用
startScript字符串(仅 WebContainers)通用
terminalHeight0100,默认 30(仅 WebContainers)通用
origin字符串(Enterprise)通用
forceEmbedLayout已废弃 → embed通用
height默认 300仅 Embed
width默认 100%仅 Embed
hideNavigation布尔仅 Embed
crossOriginIsolated→ URL 参数 corp仅 Embed
newWindow默认 true仅 Open
zenMode布尔仅 Open

模板词表

用途模板集合
SDK(8 个)angular-cli create-react-app html javascript node polymer typescript vuenode 在 WebContainers
POST API(4 个)typescript angular-cli create-react-app javascript

.stackblitzrc 字段(共 4 个)

字段取值默认
installDependencies布尔true
startCommand字符串 / falsepackage.json 推断
compileTrigger'auto' / 'keystroke' / 'save'auto
envRecord<string, string>

JSON 格式、不支持注释;也可放在 package.jsonstackblitz 字段。终端 / 控制台高度不是这里的字段(属 SDK 嵌入选项 / URL 参数)。