@smvgdev/vite-plugin-shopify-assets-sweep v1.0.3
π§Ή vite-plugin-shopify-assets-sweep
A 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.
β¨ Features
- β 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
andwriteBundle
phases
π¦ Installation
npm install vite-plugin-shopify-assets-sweep --save-dev
π Usage
In your vite.config.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,
},
};
π§Ύ static-assets.json
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:
["logo.svg", "mezereon.js", "mezereon.css.liquid"]
These filenames should match what's in the
assets/
folder exactly.
βοΈ Options
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 |
π§ͺ Dry Run Mode
Want to preview what would be deleted?
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.
π Example Project Structure
.
βββ 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
π License
MIT β feel free to use, modify, and contribute.
π¬ Feedback / Contributions
If you find this helpful or have suggestions, feel free to open an issue or PR. Happy sweeping! π§Ή