当前位置: 首页 > news >正文

重庆微信网站制作费用idc机房

重庆微信网站制作费用,idc机房,高密哪里做网站好,科技网站设计资讯参考了文章WebContainer/api 基础&#xff08;Web IDE 技术探索 一&#xff09; 在浏览器中运行vite的vue3项目 示例站点 最终效果 主要流程 加载WebContainer》加载代码压缩包>解压代码压缩包》生成文件树》挂载文件树》pnpm安装依赖》启动项目 代码 <script setup…

参考了文章WebContainer/api 基础(Web IDE 技术探索 一)

在浏览器中运行vite的vue3项目

示例站点

最终效果

在这里插入图片描述

主要流程

加载WebContainer=》加载代码压缩包=>解压代码压缩包=》生成文件树=》挂载文件树=》pnpm安装依赖=》启动项目

代码

<script setup>
import { onMounted, ref } from 'vue'
import { WebContainer } from "@webcontainer/api";
import { mountZip } from '@/views/Containers/utls.js'
const webUrl = ref("");
const codeZip = '/code/vue-project.zip'
async function initContainer() {console.log("挂载")// Call only onceconst webcontainerInstance = await WebContainer.boot();const nodeV = await webcontainerInstance.spawn("node", ["-v"]);nodeV.output.pipeTo(new WritableStream({write(data) {console.log("node -v ==>", data);},}));const fileTree =  await mountZip(codeZip)console.log('挂载文件',fileTree)// 1. 挂载文件await webcontainerInstance.mount(fileTree);console.log("ls");const ls = await webcontainerInstance.spawn("ls", ["-al"]);ls.output.pipeTo(new WritableStream({write(data) {console.log(data);},}));// 2. 下载依赖console.log("pnpm install");const install = await webcontainerInstance.spawn("pnpm", ["install"]);install.output.pipeTo(new WritableStream({write(data) {console.log(data);},}));// 3. 判断exit 状态let code = await install.exit;if (code !== 0) {console.error("error to install.");}// 4. 启动服务console.log("npm run dev");const process = await webcontainerInstance.spawn("npm", ["run","dev"]);process.output.pipeTo(new WritableStream({write(data) {console.log(data);},}));// 5. 监听服务启动webcontainerInstance.on("server-ready", (port, url) => {console.log("server-ready", url);webUrl.value = url;});
}onMounted(() => {mountZip(codeZip)initContainer()
})
</script><template>
<div><iframe :src="webUrl" style="height: 100vh;width: 100%"/>
</div>
</template><style scoped></style>

工具函数

import JSZip from 'jszip'
export async function  mountZip(zipUrl){console.log("读取zip文件",zipUrl)const fileTree = {}try {// 使用 fetch 获取 ZIP 数据const response = await fetch(zipUrl);const buffer = await response.arrayBuffer();// 使用 JSZip 处理获取到的数据const zip = new JSZip();const zipContents = await zip.loadAsync(buffer);// 处理解压后的内容for (const [relativePath, file] of Object.entries(zipContents.files)) {// console.log('relativePath',relativePath)if(file.dir){let dirList = relativePath.split('/')// console.log('dirList',dirList)if(dirList.length > 2){let tmp = fileTreefor (let i = 0; i < dirList.length - 1; i++) {// console.log('tmp(dirList[i]',tmp[dirList[i]])if(tmp[dirList[i]]){tmp = tmp[dirList[i]].directory}else{tmp[dirList[i]] = {directory: {},}}}}else{fileTree[dirList[0]] = {directory: {},}}}else{let dirList = relativePath.split('/')// console.log('dirList',dirList)if(dirList.length > 1) {let tmp = fileTreefor (let i = 0; i < dirList.length - 1; i++) {// console.log('tmp(dirList[i]', tmp[dirList[i]])if (tmp[dirList[i]]) {tmp = tmp[dirList[i]].directory} else {tmp[dirList[i]] = {directory: {},}}}// console.log('tmp',tmp)tmp[dirList[dirList.length - 1]] = {file: {contents: await file.async('string')},}}else{// console.log('根目录文件',dirList)fileTree[dirList[dirList.length - 1]] = {file: {contents: await file.async('string')},}}}}} catch (error) {console.error('获取 ZIP 数据时出错:', error);}console.log('fileTree',fileTree)return fileTree
}
http://www.yayakq.cn/news/795873/

相关文章:

  • 抚州建设工程造价管理站网站专做英文类网站
  • 网站布局有哪些背景网站建设
  • 南昌网站建设哪家好薇百度指数1000搜索量有多少
  • 手工木雕网站建设策划书wordpress自定义类型
  • 自己可以做类似淘宝客网站吗wordpress 后台链接
  • 做内贸只要有什么网络推广网站互联网编程技术
  • 给网站做seo诊断网站排名查询工具
  • 网站规划与设计大作业怎么做手机字体下载大全免费网站
  • 绍兴seo整站优化推广链接怎么自己搞定
  • 南京手机网站设计公司工装设计案例网站
  • 保定网站设计制作广州网络科技有限公司有哪些
  • 如何做黑客攻击网站个人网页设计要素
  • 淘宝客网站哪里可以做基于多站点的网站内容管理平台的管理与应用
  • 网站建设 支持多种语言wordpress iis 发布
  • 网站seo怎么做网站建设安全要求
  • 盐城整站优化网站数据分析平台
  • 做网站网络合同手工大全
  • 中卫网站网站建设wordpress如何设置4个侧边栏
  • 怎么做企业营销型网站深圳企业网站建设公司哪家好
  • 网站建设条件招聘骏域网站建设
  • destoon 网站后台显示不出模板网站开发课设个人总结
  • 嘉兴专业网站排名推广重庆装修公司排名前十名
  • 公司建网站多少钱一年网站建设咨询有客诚信网站建设咨询
  • 广东企业网站模板定制世界工业设计大学排名前25
  • 芜湖建设机械网站中国十大进出口公司排名
  • 成都保障房中心官方网站设计海报
  • 怎样在手机上建网站火锅自助餐网站建设
  • ios7 风格 网站免费网站加速器
  • 自助建站系统营销型网站建设 课程
  • 地方门户网站资讯该怎么做重庆博达建设集团网站