hello.js
Code: Select all
import { WebContainer } from 'https://cdn.jsdelivr.net/npm/@webcontainer/api/dist/index.js';
let wc;
document.addEventListener('DOMContentLoaded', async () => {
const out = document.getElementById('out');
const codeEl = document.getElementById('code-editor');
wc = await WebContainer.boot({ coep: 'require-corp' });
const runner = new Worker('./run-worker.js', { type: 'module' });
runner.onmessage = (m) => {
const { stdout, stderr, exitCode } = m.data || {};
out.textContent += stdout + (stderr ? '\n[stderr]\n' + stderr : '') + '\n[exit ' + exitCode + ']';
};
document.getElementById('run').onclick = async () => {
try {
out.textContent = 'Compiling...\n';
const code = codeEl.value || '#include \nint main(){std::cout
Mobile version