stackblitz-core-workflow-a
Build a browser-based code editor with WebContainers: file tree, editor, terminal, and preview. Use when creating interactive coding environments, building educational tools, or embedding development environments in web apps. Trigger: "webcontainer IDE", "browser IDE", "stackblitz editor", "code playground".
- License 许可
- MIT
- 最近更新
- 2026-07-13
- Stars
- ★ 1
- Forks
- 0
01 前言 Front Matter
- name
- stackblitz-core-workflow-a
- tags
- [ "saas", "ide", "webcontainers", "stackblitz" ]
- author
- Jeremy Longshore <jeremy@intentsolutions.io>
- license
- MIT
- version
- 1.0.0
- description
- Build a browser-based code editor with WebContainers: file tree, editor, terminal, and preview. Use when creating interactive coding environments, building educational tools, or embedding development environments in web apps. Trigger: "webcontainer IDE", "browser IDE", "stackblitz editor", "code playground".
- allowed-tools
- Read, Write, Edit, Bash(npm:*), Grep
- compatible-with
- claude-code
03 SKILL.md 正文
StackBlitz Core Workflow A: Browser IDE
Overview
Build a complete browser-based IDE using WebContainers: file explorer, code editor (Monaco/CodeMirror), integrated terminal (xterm.js + jsh), and live preview iframe. This is the architecture behind bolt.new.
Instructions
Step 1: HTML Layout
<div id="app">
<div id="file-tree"></div>
<div id="editor"></div>
<div id="terminal"></div>
<iframe id="preview"></iframe>
</div>
Step 2: Boot and Mount Project
import { WebContainer, FileSystemTree } from '@webcontainer/api';
const files: FileSystemTree = {
'package.json': {
file: { contents: JSON.stringify({
name: 'playground', type: 'module',
scripts: { dev: 'vite' },
dependencies: { vite: '^5.0.0' },
}) },
},
'index.html': {
file: { contents: '<!DOCTYPE html><html><body><div id="app"></div><script type="module" src="/src/main.js"></script></body></html>' },
},
src: { directory: {
'main.js': { file: { contents: 'document.getElementById("app").innerHTML = "<h1>Hello!</h1>";' } },
}},
};
const wc = await WebContainer.boot();
await wc.mount(files);
Step 3: File Tree with Live Updates
async function renderFileTree(path = '/') {
const entries = await wc.fs.readdir(path, { withFileTypes: true });
const tree = document.getElementById('file-tree')!;
for (const entry of entries) {
if (entry.name === 'node_modules') continue;
const fullPath = `${path}${path === '/' ? '' : '/'}${entry.name}`;
const el = document.createElement('div');
el.textContent = entry.isDirectory() ? `📁 ${entry.name}` : `📄 ${entry.name}`;
el.onclick = async () => {
if (!entry.isDirectory()) {
const content = await wc.fs.readFile(fullPath, 'utf-8');
editor.setValue(content); // Monaco editor
currentFile = fullPath;
}
};
tree.appendChild(el);
}
}
Step 4: Save Editor Changes to WebContainer
let currentFile = '/src/main.js';
// Monaco editor onChange
editor.onDidChangeModelContent(async () => {
const content = editor.getValue();
await wc.fs.writeFile(currentFile, content);
// Vite HMR will auto-reload the preview
});
Step 5: Terminal + Preview
// Terminal
const jsh = await wc.spawn('jsh', { terminal: { cols: 80, rows: 12 } });
jsh.output.pipeTo(new WritableStream({
write(data) { terminal.write(data); },
}));
// Install and start dev server
const install = await wc.spawn('npm', ['install']);
await install.exit;
await wc.spawn('npm', ['run', 'dev']);
// Preview iframe
wc.on('server-ready', (port, url) => {
document.getElementById('preview')!.src = url;
});
Error Handling
| Error | Cause | Solution |
|---|---|---|
| Preview blank | Server not ready yet | Wait for server-ready event |
| HMR not working | Vite not running | Check npm install succeeded |
| File tree empty | Mount failed | Verify FileSystemTree structure |
Resources
Next Steps
For embedding and sharing projects, see stackblitz-core-workflow-b.
04 同仓库更多 Skills
zustand-store-creator
Create zustand store creator operations. Auto-activating skill for Frontend Development. Triggers on: zustand store creator, zustand store creator Part of the Frontend Development skill category. Use when working with zustand store creator functionality. Trigger with phrases like "zustand store creator", "zustand creator", "zustand".
zero-trust-config-helper
Configure with zero trust config helper operations. Auto-activating skill for Security Advanced. Triggers on: zero trust config helper, zero trust config helper Part of the Security Advanced skill category. Use when configuring systems or services. Trigger with phrases like "zero trust config helper", "zero helper", "zero".
zapier-integration-helper
Assist with zapier integration helper operations. Auto-activating skill for Business Automation. Triggers on: zapier integration helper, zapier integration helper Part of the Business Automation skill category. Use when working with APIs or building integrations. Trigger with phrases like "zapier integration helper", "zapier helper", "zapier".
yaml-config-validator
Validate yaml config validator operations. Auto-activating skill for DevOps Basics. Triggers on: yaml config validator, yaml config validator Part of the DevOps Basics skill category. Use when configuring systems or services. Trigger with phrases like "yaml config validator", "yaml validator", "yaml".
xvary-stock-research
Thesis-driven equity analysis from public SEC EDGAR and market data; /analyze, /score, /compare workflows with bundled Python tools (Claude Code, Cursor, Codex).
xss-vulnerability-scanner
Scan xss vulnerability scanner operations. Auto-activating skill for Security Fundamentals. Triggers on: xss vulnerability scanner, xss vulnerability scanner Part of the Security Fundamentals skill category. Use when working with xss vulnerability scanner functionality. Trigger with phrases like "xss vulnerability scanner", "xss scanner", "xss".