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

@dune2/vite

v0.1.1

Published

面向 Vite 的编译期插件,用于处理 `createIsomorphicFn()` 同构函数链:在构建时保留 **server** 实现、去掉 **client** 分支,便于 SSR 或服务端打包。

Readme

@dune2/vite

面向 Vite 的编译期插件,用于处理 createIsomorphicFn() 同构函数链:在构建时保留 server 实现、去掉 client 分支,便于 SSR 或服务端打包。

功能特性

  • 基于 ast-grep 做 AST 级改写,不依赖 Babel
  • 仅在源码包含 createIsomorphicFn 时参与转换,无匹配则跳过
  • 默认匹配 .ts / .tsx / .js / .jsx / .mjs / .cjs,可通过 include 自定义
  • 跳过 Vite 虚拟模块(路径含 \0
  • 导出 createIsomorphicFnTransform,便于在测试或其它工具链中复用

安装

pnpm add -D @dune2/vite
pnpm add vite   # peer dependency,需由项目自行安装

支持的 Vite 版本:^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0(见 package.jsonpeerDependencies)。

使用

vite.config.ts 中注册插件(enforce: 'pre',会尽早运行):

import { defineConfig } from 'vite';
import { dune2Vite } from '@dune2/vite';

export default defineConfig({
  plugins: [dune2Vite()],
});

转换规则

下列写法在构建后都会变成 server 侧实现;若无 server 则替换为 () => {}

| 源码 | 构建结果 | | ------------------------------------------ | ---------- | | createIsomorphicFn().server(s).client(c) | s | | createIsomorphicFn().client(c).server(s) | s | | createIsomorphicFn().server(s) | s | | createIsomorphicFn().client(c) | () => {} | | createIsomorphicFn() | () => {} |

示例:

// 输入
export const log = createIsomorphicFn()
  .server((m) => console.log('server:', m))
  .client((m) => console.log('client:', m));

// 输出
export const log = (m) => console.log('server:', m);

嵌套或重叠的匹配会按更长模式优先处理,避免重复替换。

配置项

interface Dune2ViteOptions {
  /** 参与扫描的文件路径正则,默认 /\.[mc]?[jt]sx?$/ */
  include?: RegExp;
}

示例:只处理 .ts / .tsx

dune2Vite({ include: /\.tsx?$/ });

高级用法

插件还导出 createIsomorphicFnTransform,可在自定义 AST 流水线里复用与插件相同的改写规则(需自行 parse / commitEdits,用法见 src/transforms/createIsomorphicFn.ts)。

开发

在 monorepo 根目录或本包目录:

cd packages/vite
pnpm run build   # 类型检查 + tsdown 打包
pnpm run test