CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-laravel-vite-plugin

Laravel plugin for Vite that enables seamless integration between Laravel applications and Vite's build tooling with SSR support and Inertia.js helpers

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

asset-management.mddocs/

Asset Management

CLI tools and utilities for managing compiled assets, including cleanup of orphaned files that are no longer referenced in Vite manifests.

Capabilities

Clean Orphaned Assets CLI

Command-line tool for removing orphaned assets that are no longer referenced in the Vite manifest files.

# Basic usage
clean-orphaned-assets

# With custom manifest path
clean-orphaned-assets --manifest=./custom/path/manifest.json

# For SSR builds
clean-orphaned-assets --ssr

# With custom assets directory
clean-orphaned-assets --assets=./public/assets

# Dry run to see what would be removed
clean-orphaned-assets --dry-run

# Quiet mode (suppress output)
clean-orphaned-assets --quiet

CLI Options

Complete command-line options for the asset cleanup tool:

--manifest=<path>    # Specify custom manifest file path
--ssr                # Use SSR manifest file locations
--assets=<path>      # Specify custom assets directory path
--dry-run            # Preview what would be removed without deleting
--quiet              # Suppress all output messages

Default Behavior:

  • Regular builds: Looks for ./public/build/manifest.json
  • SSR builds: Looks for ./bootstrap/ssr/ssr-manifest.json and ./bootstrap/ssr/manifest.json
  • Assets directory: Uses manifest directory + /assets (e.g., ./public/build/assets)

Usage Examples:

# Clean regular build assets
clean-orphaned-assets

# Clean SSR build assets
clean-orphaned-assets --ssr

# Preview what would be cleaned without actually deleting
clean-orphaned-assets --dry-run

# Clean with custom paths
clean-orphaned-assets \
  --manifest=./dist/manifest.json \
  --assets=./dist/assets

# Silent cleanup for CI/CD scripts
clean-orphaned-assets --quiet

Manifest Processing

The asset cleanup tool processes different types of Vite manifests:

Regular Build Manifest

Standard Vite manifest format with asset references:

{
  "resources/js/app.js": {
    "file": "assets/app-abc123.js",
    "src": "resources/js/app.js",
    "isEntry": true,
    "css": ["assets/app-def456.css"]
  }
}

SSR Manifest

Server-side rendering manifest with array format:

{
  "resources/js/ssr.js": [
    "assets/ssr-abc123.js",
    "assets/shared-def456.js"
  ]
}

Asset Detection Logic

The cleanup process follows these steps:

  1. Locate Manifest: Find the appropriate manifest file based on options
  2. Parse Manifest: Extract all referenced asset files from the manifest
  3. Scan Assets Directory: List all files in the assets directory
  4. Identify Orphans: Compare assets directory files against manifest references
  5. Remove Orphans: Delete files not referenced in the manifest (unless dry-run)

Integration with Build Process

The asset cleanup tool can be integrated into your build workflow:

Package.json Scripts

{
  "scripts": {
    "build": "vite build",
    "build:clean": "vite build && clean-orphaned-assets",
    "build:ssr": "vite build --ssr && clean-orphaned-assets --ssr",
    "clean:assets": "clean-orphaned-assets",
    "clean:preview": "clean-orphaned-assets --dry-run"
  }
}

CI/CD Integration

#!/bin/bash
# Build assets
npm run build

# Clean orphaned assets quietly
clean-orphaned-assets --quiet

# Verify build completed successfully
if [ $? -eq 0 ]; then
  echo "Build and cleanup completed successfully"
else
  echo "Build or cleanup failed"
  exit 1
fi

Safety Features

The cleanup tool includes several safety mechanisms:

  • Dry Run Mode: Preview changes without making modifications
  • Manifest Validation: Ensures manifest file exists and is valid JSON
  • Path Validation: Verifies assets directory exists before scanning
  • Error Handling: Graceful handling of file system errors
  • Logging: Detailed output of operations performed (unless quiet mode)

Output Examples

Normal Operation

Reading manifest [./public/build/manifest.json].
Non-SSR manifest found.
Verify assets in [./public/build/assets].
[3] orphaned assets found.
Removing orphaned asset [./public/build/assets/old-file-123.js].
Removing orphaned asset [./public/build/assets/unused-456.css].
Removing orphaned asset [./public/build/assets/legacy-789.png].

Dry Run Mode

Reading manifest [./public/build/manifest.json].
Non-SSR manifest found.
Verify assets in [./public/build/assets].
[2] orphaned assets found.
Orphaned asset [./public/build/assets/old-file-123.js] would be removed.
Orphaned asset [./public/build/assets/unused-456.css] would be removed.

No Orphaned Assets

Reading manifest [./public/build/manifest.json].
Non-SSR manifest found.
Verify assets in [./public/build/assets].
No orphaned assets found.

docs

asset-management.md

index.md

inertia-helpers.md

plugin-configuration.md

tile.json