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-plugin-base-output

v1.0.3

Published

Vite 插件:根据 base 配置将构建产物输出到 dist/<base>/ 目录,便于子路径部署

Readme

vite-plugin-base-output

一个用于 Vite 构建产物按 base 目录输出 的小插件。

它解决什么问题

当你把站点部署到子路径(例如 https://example.com/app/)时,通常会配置:

// vite.config.ts
export default defineConfig({
  base: '/app/',
})

此时 Vite 默认仍然输出到:

dist/
  assets/
  index.html

而有些部署环境更希望你的产物目录直接长成:

dist/
  app/
    assets/
    index.html

本插件会在 build 结束后 自动把 dist 下(除隐藏文件与目标目录外)的内容移动到 dist/<base>/ 目录中。

安装

pnpm add -D vite-plugin-base-output

使用

// vite.config.ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import baseOutput from 'vite-plugin-base-output'

export default defineConfig({
  base: '/app/',
  plugins: [
    vue(),
    baseOutput(),
  ],
})

也支持直接传入字符串(会覆盖 config.base):

plugins: [
  vue(),
  baseOutput('/app/'), // 也可以 baseOutput('app')
]

行为说明

  • 优先级
    • 如果你调用 baseOutput('xxx/yyy') 并传入了字符串,则以传入值为准(覆盖 config.base)。
    • 否则在 configResolved 阶段读取 config.base
  • base 为 URL 时跳过:如果 basehttp://https:// 开头,会直接跳过(不做任何移动)。
  • 标准化路径:会把 base 两端的 / 去掉,例如:
    • '/app/''app'
    • 'app/''app'
    • '/''' → 不处理
  • 构建后移动:在 closeBundle 阶段把 dist/*(排除 dist/<base>/ 本身与隐藏文件)移动到 dist/<base>/*
  • 覆盖同名目标:如果目标位置已存在同名文件/目录,会先删除再移动。

示例

输入

  • base: '/app/'
  • dist/ 初始结构:
dist/
  assets/
  index.html

输出

dist/
  app/
    assets/
    index.html

注意事项

  • 只用于 build:它在 closeBundle 执行,适合构建产物整理,不影响 dev server。

License

ISC