1.0.3 β€’ Published 3 months ago

@smvgdev/vite-plugin-shopify-assets-sweep v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

🧹 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 and writeBundle 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

OptionTypeDefaultDescription
manifestFileNamestring"assets/manifest.json"Path to the Vite-generated manifest file
themeRootstring"assets"Directory containing your Shopify theme assets
staticManifestFileNamestring"static-assets.json"Path to JSON file listing static assets to preserve
dryRunbooleanfalseIf 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! 🧹

1.0.3

3 months ago

1.0.2

3 months ago

1.0.1

3 months ago

1.0.0

3 months ago