@driver-digital/vite-plugin-shopify-clean

中文文档
2.0.2发布于 2026/10/06MITTypeScriptESM + CJS零依赖近 30 天下载 1.1万

Vite plugin for correctly cleaning up an assets folder

原始使用文档
文档目录8 节
  1. Features
  2. Installation
  3. Usage
  4. Options
  5. How it works
  6. Changelog
  7. License
  8. Acknowledgements

@driver-digital/vite-plugin-shopify-clean

Vite plugin that cleans up your Shopify theme assets/ folder across builds and during watch (HMR). It is designed to be used alongside Barrel's Shopify Vite Plugin.

Why you might need this: when Vite emits hashed filenames (e.g., app-abc123.js), older hashed files can accumulate over time. This plugin removes outdated assets safely so your assets/ directory stays tidy and your theme only references current files.

GitHub

npm

Issues

Changelog

Features

  • Cleans pre-existing assets listed in the last manifest at the start of a build.
  • Removes stale assets after each build by comparing the previous manifest to the current one — in both dev (watch) and production builds.
  • Tracks JS, CSS, and asset files (images, fonts, etc.) from the manifest. Sourcemap (.map) files aren't in the manifest, so they aren't cleaned.
  • Uses Rollup/Vite watchMode (no env var required) to control watch-specific behavior.
  • Works with the Shopify theme assets directory structure.
  • Minimal configuration; sensible defaults.

Installation

npm i -D @driver-digital/vite-plugin-shopify-clean

Peer requirements:

  • Node.js: ^20.19.0 || >=22.12.0
  • Vite: >=6

Usage

Add the plugin to your Vite config alongside Barrel's Shopify Vite Plugin.

// vite.config.js
import { defineConfig } from 'vite'
import shopify from 'vite-plugin-shopify'
import shopifyClean from '@driver-digital/vite-plugin-shopify-clean'

export default defineConfig({
  build: {
    emptyOutDir: false,
    sourcemap: true
  },
  plugins: [
    shopifyClean({
      // themeRoot: './',
      // manifestFileName: '.vite/manifest.json',
    }),
    shopify({
      tunnel: true,
      themeRoot: ".",
      sourceCodeDir: "frontend"
    })
  ],
})

Notes:

  • When outputting directly to your Shopify theme assets/ folder, set build.emptyOutDir: false. The plugin relies on the previous build's files and manifest to determine what to remove. If Vite empties the directory first, there is nothing to compare and the cleanup cannot run as intended (and you generally don't want Vite to wipe your theme assets).
  • The plugin expects a Vite manifest to exist within your theme assets/ directory (by default at assets/.vite/manifest.json). If your integration writes the manifest elsewhere, configure manifestFileName or themeRoot accordingly.
  • In watch mode, the plugin automatically handles cleanup as new files are emitted.

Options

interface VitePluginShopifyCleanOptions {
  /**
   * Relative location of the manifest inside the theme's assets directory.
   * Defaults to `.vite/manifest.json` (resolved under `assets/`).
   */
  manifestFileName?: string

  /**
   * Shopify theme root directory (relative to the directory Vite is run from).
   * Defaults to `./`.
   */
  themeRoot?: string
}

Defaults used by the plugin:

  • manifestFileName: .vite/manifest.json
  • themeRoot: ./

How it works

The plugin tracks files listed in Vite's manifest (JS, CSS, and asset files like images and fonts) and uses manifest comparison to determine what to clean.

  • Build start (buildStart)
    • If assets/.vite/manifest.json exists (or your configured path), the plugin reads the previously emitted assets and removes them from assets/ before a fresh build. This prevents stale files from lingering across builds.
  • Write bundle (writeBundle)
    • After new assets are written, the plugin compares the previous manifest to the current one. Any files that were in the old manifest but are no longer in the new manifest are deleted. This handles cases where entry points are renamed or removed between builds.

Changelog

See CHANGELOG.md for release notes.

License

MIT

Acknowledgements

Built and maintained with ♥️ by Driver Digital

Originally forked from @by-association-only/vite-plugin-shopify-clean - big thanks to Dan Gamble for his work on the original.

版本与发布记录

@driver-digital/vite-plugin-shopify-clean 共发布 12 个版本,首次发布于 2025/09/23;过去 12 个月发布了 9 个版本。

版本发布日期距今
2.0.2latest2026/10/061 个月前
2.0.12026/08/202 个月前
2.0.02026/04/176 个月前
1.1.22026/02/188 个月前
1.1.12026/01/249 个月前
1.1.02026/01/239 个月前

关于 @driver-digital/vite-plugin-shopify-clean 的常见问题

@driver-digital/vite-plugin-shopify-clean 是什么?

Vite plugin for correctly cleaning up an assets folder

如何安装 @driver-digital/vite-plugin-shopify-clean?

在项目目录运行 npm install @driver-digital/vite-plugin-shopify-clean,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:vite(>=6.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@driver-digital/vite-plugin-shopify-clean 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@driver-digital/vite-plugin-shopify-clean 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@driver-digital/vite-plugin-shopify-clean 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js ^20.19.0 || >=22.12.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@driver-digital/vite-plugin-shopify-clean 可以商用吗?

@driver-digital/vite-plugin-shopify-clean 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@driver-digital/vite-plugin-shopify-clean 的下载量有多少?

根据 npm 官方下载统计,@driver-digital/vite-plugin-shopify-clean 在 2026/10/13 – 2026/11/11 这 30 天内被下载 10,673 次,日均约 356 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@driver-digital/vite-plugin-shopify-clean 还在维护吗?

最新版本 2.0.2 发布于 2026/10/06(1 个月前);至今共发布 12 个版本,其中过去 12 个月发布了 9 个;首次发布于 2025/09/23。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。