generated from template/vite-react-template
可以获取已有的projectId的内容
This commit is contained in:
0
src/demo2/index.ts
Normal file
0
src/demo2/index.ts
Normal file
77
src/demo2/main.ts
Normal file
77
src/demo2/main.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
import sdk from '@stackblitz/sdk';
|
||||
|
||||
const main = async () => {
|
||||
const vm = await sdk.embedProject(
|
||||
'editor',
|
||||
{
|
||||
files: {
|
||||
'index.html': `<h1>Hello World</h1>`,
|
||||
'style.css': `body { background-color: #f0f0f0; }`,
|
||||
'.pkgignore': `node_modules`,
|
||||
// '.env': `TEMP_TOKEN=1234567890`,
|
||||
'package.json': `{
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"lint": "eslint ."
|
||||
},
|
||||
"dependencies": {
|
||||
"vite": "^6.0.0",
|
||||
"@kevisual/envision-cli": "^0.0.32"
|
||||
},
|
||||
"startCommand": "pnpm i && pnpm dev"
|
||||
}`,
|
||||
},
|
||||
title: 'Hello World',
|
||||
template: 'node',
|
||||
settings: {},
|
||||
},
|
||||
{
|
||||
view: 'preview',
|
||||
clickToLoad: true,
|
||||
height: '500px',
|
||||
width: '800px',
|
||||
// hideDevTools: true,
|
||||
// hideExplorer: true,
|
||||
// hideNavigation: true,
|
||||
},
|
||||
);
|
||||
await vm.applyFsDiff({
|
||||
create: {
|
||||
// '.env': `TEMP_TOKEN=1234567890`,
|
||||
'b.txt': `#!/bin/jsh
|
||||
echo "Hello, World!"
|
||||
`,
|
||||
},
|
||||
destroy: [],
|
||||
});
|
||||
const iframe = document.querySelector('iframe');
|
||||
// @ts-ignore
|
||||
window.vm = vm;
|
||||
iframe?.addEventListener('load', () => {
|
||||
// vm.postMessage('hello', '*');
|
||||
const noTagLinks = document.createElement('style');
|
||||
noTagLinks.innerHTML = `
|
||||
.MenuBar-LogoLink_embedded-Yljpv {
|
||||
display: none;
|
||||
}
|
||||
`;
|
||||
iframe?.contentWindow?.document.appendChild(noTagLinks);
|
||||
console.log(iframe?.contentWindow?.document);
|
||||
});
|
||||
};
|
||||
// main();
|
||||
// const actions = document.getElementById('actions');
|
||||
// actions?.addEventListener('click', () => {
|
||||
// main();
|
||||
// });
|
||||
|
||||
const main2 = async () => {
|
||||
const vm = await sdk.embedProjectId('editor', 'sb1-j7dqwtjx');
|
||||
setTimeout(async () => {
|
||||
// vm.postMessage('hello', '*');
|
||||
const res = await vm.getFsSnapshot();
|
||||
console.log(res);
|
||||
}, 1000);
|
||||
};
|
||||
main2();
|
||||
Reference in New Issue
Block a user