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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ggcv/vite-plugin-ssg

v1.0.1

Published

Vite plugin for Static Site Generation (SSG) — prerender Vue/React apps to static HTML at build time

Downloads

174

Readme

vite-plugin-ssg

起因

由于作者在vite项目中弄了一个多入口的MPA多页应用,每个页面都需要SSG渲染

使用 vite-ssg 包进行SSG时发现这个包似乎对多入口的应用不起作用,所以请 Ai 设计了这么一个Vite SSG插件

设计理念

核心原则:

  1. 零项目假设 — 不假设任何目录结构(.generatedhtml 子目录等)
  2. 框架无关 — 默认支持 Vue,但通过 render 回调可用于 React、Solid 等任何框架
  3. 显式优于隐式 — 用户声明 entries 列表,而非扫描某个约定目录
  4. 配置继承 — 自动从 Vite resolvedConfig 中继承 rootoutDiralias
  5. 无需SSR判断 — 内部自带浏览器环境mock,虽然不保证百分百覆盖,但能减少非常多的SSR环境判断

API 概览

核心选项

| 选项 | 类型 | 说明 | | ---------------- | ---------------------------------- | -------------------------------------------- | | entries ⚡必填 | SSGEntry[] | () => SSGEntry[] | 需要预渲染的页面列表 | | render | (ctx) => { html } | 自定义渲染函数(默认 Vue SSR) | | ssrViteConfig | UserConfig | SSR 服务器的 Vite 配置覆盖 | | mock | boolean | 是否安装 happy-dom Mock(默认 true) | | appSelector | string | HTML 占位标记(默认 <div id="app"></div>) | | createAppFn | string | 入口导出函数名(默认 createApp) | | enabled | boolean | 是否启用(默认 true) |

SSGEntry 结构

interface SSGEntry {
  entry: string; // SSR 入口模块路径(供 vite.ssrLoadModule 加载)
  html: string; // 输出 HTML 路径(相对于 build.outDir)
}

使用示例

Vue 单页应用(最简)

ssgPlugin({
  entries: [{ entry: "./src/main.ts", html: "index.html" }],
});

Vue 多页应用

ssgPlugin({
  entries: [
    { entry: "./src/pages/home/main.ts", html: "index.html" },
    { entry: "./src/pages/about/main.ts", html: "about/index.html" },
  ],
  ssrViteConfig: {
    ssr: { noExternal: ["naive-ui"] },
  },
});

动态生成入口

ssgPlugin({
  entries: async () => {
    const pages = await scanPages("./src/pages");
    return pages.map((p) => ({ entry: p.entry, html: p.output }));
  },
});

自定义渲染(React)

ssgPlugin({
  entries: [{ entry: "./src/main.tsx", html: "index.html" }],
  mock: false,
  render: async ({ module, html }) => {
    const { renderToString } = await import("react-dom/server");
    const appHtml = renderToString(module.default());
    return {
      html: html.replace('<div id="root"></div>', `<div id="root">${appHtml}</div>`),
    };
  },
});