{"id":15194929,"url":"https://github.com/tphp/koa-vite","last_synced_at":"2026-03-03T21:31:15.932Z","repository":{"id":143804352,"uuid":"431743552","full_name":"tphp/koa-vite","owner":"tphp","description":"koa-vite实现","archived":false,"fork":false,"pushed_at":"2021-12-01T08:55:16.000Z","size":4,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-11-29T15:29:39.089Z","etag":null,"topics":["koa","vite"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tphp.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-11-25T06:53:04.000Z","updated_at":"2021-12-01T08:55:13.000Z","dependencies_parsed_at":null,"dependency_job_id":"f1381a4c-537d-4602-a530-0cd4aa95ed7d","html_url":"https://github.com/tphp/koa-vite","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/tphp/koa-vite","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tphp%2Fkoa-vite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tphp%2Fkoa-vite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tphp%2Fkoa-vite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tphp%2Fkoa-vite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tphp","download_url":"https://codeload.github.com/tphp/koa-vite/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tphp%2Fkoa-vite/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30062347,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-03T18:21:05.932Z","status":"ssl_error","status_checked_at":"2026-03-03T18:20:59.341Z","response_time":61,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["koa","vite"],"created_at":"2024-09-27T23:03:06.228Z","updated_at":"2026-03-03T21:31:15.907Z","avatar_url":"https://github.com/tphp.png","language":"JavaScript","readme":"## 使用说明\n\n- 使用基本步骤请参考: [koa-web](https://www.npmjs.com/package/koa-web)\n- vite转发机制，[koa-vite](https://www.npmjs.com/package/koa-vite)\n- 开发模式： koa服务转发到vite服务\n- 生产模式： 直接以koa为服务器运行dist文件\n\n### 安装 vite\n\n```\nnpm init @vitejs/app\n# 选择 vue\ncd vite-project\nnpm install\n```\n\n#### 安装 koa-vite\n\n```\nnpm i koa-vite\n```\n\n#### 启动程序，如:start.js\n\n- 运行dev: node start.js\n- 运行生产环境: node start.js preview\n- build: vite build\n\n```js\nconst Koa = require(\"koa\");\nconst KoaWeb = require('koa-web');\nconst KoaVite = require('koa-vite');\nconst app = new Koa();\n\nconst config = {\n  path: __dirname,\n  json: {\n    layout: \"@layout/index\"\n  },\n  vite: {\n    server: {\n      // vite 主机名\n      host: '0.0.0.0',\n\n      // vite 端口\n      port: 3010,\n      \n      // 端口暂用退出\n      strictPort: true,\n    },\n  \n    api: {\n      // koa-web 域名\n      host: 'localhost',\n      \n      // koa-web 端口\n      port: 3000,\n\n      // 构建模板， 默认 dist\n      // dist: '../dist/',\n      \n      // vite根路径， 默认为空\n      src: './vite/'\n    }\n  }\n};\n\nKoaWeb(KoaVite(config));\n\napp.use(KoaWeb(config));\n\nconst { api } = config.vite;\napp.listen(api.port, () =\u003e {\n  const port = `\\x1B[1m${api.port}\\x1B[22m`;\n  const link = `\\x1B[36mhttp://${api.host}:${port}/\\x1B[39m`;\n  process.stdout.write(`\\n  \u003e koa-web:  ${link}\\n`);\n});\n```\n\n---\n\n## 主目录已设置到vite\n\n- 需要把src和public文件夹移动到vite目录\n\n#### 创建test页面: /vite/test.html\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n  \u003chead\u003e\n    \u003cmeta charset=\"UTF-8\" /\u003e\n    \u003clink rel=\"icon\" href=\"/favicon.ico\" /\u003e\n    \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" /\u003e\n    \u003ctitle\u003eVite App\u003c/title\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003cdiv id=\"app\"\u003e\u003c/div\u003e\n    \u003cscript type=\"module\" src=\"/static/test.js\"\u003e\u003c/script\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\n#### 创建html页面: /vite/static/test.js\n```js\nimport { createApp } from 'vue'\nimport App from '../src/components/MyTest.vue'\n\ncreateApp(App).mount('#app')\n```\n\n#### 创建数据控制页面: /vite/src/components/MyTest.vue\n\n```html\n\u003ctemplate\u003e\n  \u003cdiv class=\"my\"\u003eMy Test\u003c/div\u003e\n\u003c/template\u003e\n\n\u003cstyle scoped\u003e\n.my {\n  color: #e23e59;\n}\n\u003c/style\u003e\n```\n\n- 访问: http://localhost:3000/test.html （查看源码）\n- 或者: http://localhost:3000/test\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n  \u003chead\u003e\n    \u003cscript type=\"module\" src=\"/@vite/client\"\u003e\u003c/script\u003e\n\n    \u003cmeta charset=\"UTF-8\" /\u003e\n    \u003clink rel=\"icon\" href=\"/favicon.ico\" /\u003e\n    \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" /\u003e\n    \u003ctitle\u003eVite App\u003c/title\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003cdiv id=\"app\"\u003e\u003c/div\u003e\n    \u003cscript type=\"module\" src=\"/static/test.js\"\u003e\u003c/script\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\n- 访问: http://localhost:3000/static/test.js （查看源码）\n\n```js\nimport { createApp } from '/@fs/home/node/vite/node_modules/.vite/vue.js?v=76df34b2'\nimport App from '/src/components/MyTest.vue'\n\ncreateApp(App).mount('#app')\n```\n\n#### 创建layout页面: /html/layout/index.html\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n\n\u003chead\u003e\n  \u003ctitle\u003eKoa-Vite\u003c/title\u003e\n\u003c/head\u003e\n\n\u003cbody\u003e\n  {{ __layout__ | safe }}\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\n#### 创建html页面: /html/my.html\n\n```js\n\u003cdiv\u003ehello\u003c/div\u003e\n```\n\n- 访问: http://localhost:3000/my （查看源码）\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n\n\u003chead\u003e\n  \u003ctitle\u003eKoa-Vite\u003c/title\u003e\n\u003c/head\u003e\n\n\u003cbody\u003e\n  \u003cdiv\u003ehello\u003c/div\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftphp%2Fkoa-vite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftphp%2Fkoa-vite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftphp%2Fkoa-vite/lists"}