npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

koa-vite

v1.0.3

Published

koa vite

Downloads

3

Readme

使用说明

  • 使用基本步骤请参考: koa-web
  • vite转发机制,koa-vite
  • 开发模式: koa服务转发到vite服务
  • 生产模式: 直接以koa为服务器运行dist文件

安装 vite

npm init @vitejs/app
# 选择 vue
cd vite-project
npm install

安装 koa-vite

npm i koa-vite

启动程序,如:start.js

  • 运行dev: node start.js
  • 运行生产环境: node start.js preview
  • build: vite build
const Koa = require("koa");
const KoaWeb = require('koa-web');
const KoaVite = require('koa-vite');
const app = new Koa();

const config = {
  path: __dirname,
  json: {
    layout: "@layout/index"
  },
  vite: {
    server: {
      // vite 主机名
      host: '0.0.0.0',

      // vite 端口
      port: 3010,
      
      // 端口暂用退出
      strictPort: true,
    },
  
    api: {
      // koa-web 域名
      host: 'localhost',
      
      // koa-web 端口
      port: 3000,

      // 构建模板, 默认 dist
      // dist: '../dist/',
      
      // vite根路径, 默认为空
      src: './vite/'
    }
  }
};

KoaWeb(KoaVite(config));

app.use(KoaWeb(config));

const { api } = config.vite;
app.listen(api.port, () => {
  const port = `\x1B[1m${api.port}\x1B[22m`;
  const link = `\x1B[36mhttp://${api.host}:${port}/\x1B[39m`;
  process.stdout.write(`\n  > koa-web:  ${link}\n`);
});

主目录已设置到vite

  • 需要把src和public文件夹移动到vite目录

创建test页面: /vite/test.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <link rel="icon" href="/favicon.ico" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Vite App</title>
  </head>
  <body>
    <div id="app"></div>
    <script type="module" src="/static/test.js"></script>
  </body>
</html>

创建html页面: /vite/static/test.js

import { createApp } from 'vue'
import App from '../src/components/MyTest.vue'

createApp(App).mount('#app')

创建数据控制页面: /vite/src/components/MyTest.vue

<template>
  <div class="my">My Test</div>
</template>

<style scoped>
.my {
  color: #e23e59;
}
</style>
  • 访问: http://localhost:3000/test.html (查看源码)
  • 或者: http://localhost:3000/test
<!DOCTYPE html>
<html lang="en">
  <head>
    <script type="module" src="/@vite/client"></script>

    <meta charset="UTF-8" />
    <link rel="icon" href="/favicon.ico" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Vite App</title>
  </head>
  <body>
    <div id="app"></div>
    <script type="module" src="/static/test.js"></script>
  </body>
</html>
  • 访问: http://localhost:3000/static/test.js (查看源码)
import { createApp } from '/@fs/home/node/vite/node_modules/.vite/vue.js?v=76df34b2'
import App from '/src/components/MyTest.vue'

createApp(App).mount('#app')

创建layout页面: /html/layout/index.html

<!DOCTYPE html>
<html lang="en">

<head>
  <title>Koa-Vite</title>
</head>

<body>
  {{ __layout__ | safe }}
</body>
</html>

创建html页面: /html/my.html

<div>hello</div>
  • 访问: http://localhost:3000/my (查看源码)
<!DOCTYPE html>
<html lang="en">

<head>
  <title>Koa-Vite</title>
</head>

<body>
  <div>hello</div>
</body>
</html>