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

vite-mjs-to-zjs

v1.0.4

Published

<h1 align="center">vite-mjs-to-zjs</h1>

Downloads

26

Readme

安装

npm i vite-mjs-to-zjs -D

使用

vite.config.ts

import { defineConfig } from 'vite'
import { resolve } from 'path'
import zdjl from './src'

export default defineConfig({
  plugins: [
    zdjl()
  ],
  build: {
    minify: false, 
    lib: {
      entry: resolve(__dirname, './src/index.ts'),
      formats: ['es'], // 必须, 转换使用 mjs 文件作为基础
    }
  }
})

选项

type OptionOutputFormats = 'zjs' | 'cjs'

export interface PluginOption {
  /**
   * 依赖别名(仅替换名字)
   */
  alias?: Record<string, string>,
  /**
   * 删除该模块的导入语句
   */
  removeImport?: string[]
  /**
   * 删除副作用导入
   * @default true
   */
  removeSideEffectImport?: boolean
  /**
   * 使用另一个 zjs 文件作为生成文件的基础模板
   */
  template?: {
    /**
     * 模板文件路径
     */
    filepath?: string
    /**
     * 生成的动作插入的位置, 例如 1 则插入为第 1 个动作, 2 同理, 超出边界则插入为最后一个动作
     * @default Infinity
     */
    insertTo?: number
  },
  /**
   * 输出选项
   */
  output?: {
    /**
     * 输出目录
     */
    outdir?: string
    /**
     * 输出文件名
     */
    filename?: string
    /**
     * 输出格式
     */
    formats?: OptionOutputFormats[]
  },
  /**
   * zjs 脚本全局属性
   */
  manifest?: {
    [x: string]: any
    /**
     * 默认等待(ms)
     * @default "0"
     */
    delay?: string,
    /**
     * 动作失败后暂停
     * @default true
     */
    pauseOnFail?: boolean,
  }
}

已知问题

无法处理动态导入

vite默认会将动态导入(import())拆分为单独的文件, 插件无法处理, 得到的文件内容不正确

解决方案

内联动态导入

  1. 在 vite 配置中设置 build.rollupOptions.output.inlineDynamicImportstrue

    注意: 内联动态导入会将模块所有内容合并, 无法进行 tree-shaking 优化

从网络导入

  1. build.rollupOptions.external 中排除模块

    插件会将 ESM 模块语法转为 CJS 模块语法, 排除模块后 zdjl 将从网络载入

  2. (可选)在插件选项 alias 中设置别名, 例如: alias: {axios: 'https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js'}