Sweeps away stale Vite build artifacts from the Shopify assets folder, preserving static files via a static-assets manifest.
npm install @smvgdev/vite-plugin-shopify-assets-sweepA Vite plugin that cleans up stale assets from your Shopify theme's assets/ folder based on the current Vite manifest β while preserving static files defined in a static-assets manifest. Ideal for keeping your Shopify repo clean and deploy-ready without clutter from old build artifacts. This was build with the Shopify Paper theme in mind, but should work with any Shopify theme that uses Vite.
---
- β
Automatically removes outdated hashed build files
- β
Preserves files you define in static-assets.json
- β
Supports dryRun mode for safe previewing
- β
Works with Shopifyβs assets/ theme directory
- β
Runs during both buildStart and writeBundle phases
---
``bash`
npm install vite-plugin-shopify-assets-sweep --save-dev
---
In your vite.config.ts:
`ts
import shopify from "vite-plugin-shopify";
import shopifyAssetsSweep from "vite-plugin-shopify-assets-sweep";
export default {
plugins: [
shopify({
sourceCodeDir: "src",
entrypointsDir: "src/entrypoints",
snippetFile: "assets.liquid",
}),
shopifyAssetsSweep({
manifestFileName: "assets/manifest.json",
staticManifestFileName: "static-assets.json",
dryRun: false,
}),
],
build: {
emptyOutDir: false,
},
};
`
---
Place this file in the root of your project. It should list all the static assets you want to preserve, even if they arenβt in the current Vite manifest:
`json`
["logo.svg", "mezereon.js", "mezereon.css.liquid"]
> These filenames should match what's in the assets/ folder exactly.
---
| Option | Type | Default | Description |
| ------------------------ | --------- | ------------------------ | ----------------------------------------------------------- |
| manifestFileName | string | "assets/manifest.json" | Path to the Vite-generated manifest file |themeRoot
| | string | "assets" | Directory containing your Shopify theme assets |staticManifestFileName
| | string | "static-assets.json" | Path to JSON file listing static assets to preserve |dryRun
| | boolean | false | If true, logs deletions but doesn't actually remove files |
---
Want to preview what would be deleted?
`ts`
shopifyAssetsSweep({
dryRun: true,
});
This will output logs like:
``
[Dry Run] buildStart: Would delete old-script-abc123.js
[Dry Run] writeBundle: Would delete legacy-style-def456.css
No files are removed during dry run.
---
```
.
βββ assets/
β βββ main-abc123.js
β βββ old-main-def456.js β will be deleted
β βββ logo.svg β preserved via static-assets.json
β βββ manifest.json β current Vite manifest
βββ src/
β βββ ...
βββ static-assets.json β list of static assets to preserve
βββ vite.config.ts
---
MIT β feel free to use, modify, and contribute.
---
If you find this helpful or have suggestions, feel free to open an issue or PR. Happy sweeping! π§Ή