Command Line Tools
Asset Management Commands
Asset Management Commands
Section titled “Asset Management Commands”The Wheels CLI provides commands for managing static assets in your application, including compilation, optimization, and cleanup of JavaScript, CSS, and image files.
Available Commands
Section titled “Available Commands”wheels assets precompilewheels assets cleanwheels assets clobberAsset Commands
Section titled “Asset Commands”wheels assets precompile
Section titled “wheels assets precompile”Prepares your assets for production deployment by minifying and optimizing them.
# Basic precompilation (defaults to production)wheels assets precompile
# Force recompilation of all assetswheels assets precompile --force
# Target specific environments (with aliases)wheels assets precompile --environment=production # Full minificationwheels assets precompile --environment=prod # Alias for productionwheels assets precompile --environment=staging # Light minificationwheels assets precompile --environment=stage # Alias for stagingwheels assets precompile --environment=testing # Light minificationwheels assets precompile --environment=test # Alias for testingwheels assets precompile --environment=maintenance # Light minificationwheels assets precompile --environment=development # No minificationwheels assets precompile --environment=dev # Alias for developmentEnvironment-Specific Processing
Section titled “Environment-Specific Processing”The command applies different levels of asset optimization based on the target environment:
- Production (
production,prod): Full minification - Maximum compression, removes all comments and whitespace, optimizes code structure - Staging (
staging,stage): Light minification - Removes comments and excessive whitespace but preserves some formatting for debugging - Testing (
testing,test): Light minification - Same as staging, optimized for testing environments - Maintenance (
maintenance): Light minification - Minimal processing for maintenance mode deployments - Development (
development,dev): No minification - Preserves original formatting and comments for debugging
What it does
Section titled “What it does”- Minifies JavaScript files: Removes comments, whitespace, and unnecessary characters (level depends on environment)
- Minifies CSS files: Removes comments, whitespace, and optimizes CSS rules (level depends on environment)
- Generates cache-busted filenames: Adds MD5 hashes to filenames (e.g.,
application-a1b2c3d4.min.js) - Creates manifest.json: Maps original filenames to compiled versions
- Processes images: Copies images with cache-busted names
- Output location: Stores all compiled assets in
/public/assets/compiled/
Generated Manifest Example
Section titled “Generated Manifest Example”{ "application.js": "application-a1b2c3d4.min.js", "admin.js": "admin-b2c3d4e5.min.js", "styles.css": "styles-c3d4e5f6.min.css", "admin.css": "admin-d4e5f6g7.min.css", "logo.png": "logo-e5f6g7h8.png", "banner.jpg": "banner-f6g7h8i9.jpg"}wheels assets clean
Section titled “wheels assets clean”Removes old compiled assets while keeping recent versions for rollback capability.
# Clean old assets (keeps 3 most recent versions by default)wheels assets clean
# Keep 5 versions of each assetwheels assets clean --keep=5
# Preview what would be deleted without actually deletingwheels assets clean --dryRunWhat it does
Section titled “What it does”- Identifies old versions: Finds all compiled assets with hash fingerprints
- Keeps recent versions: Retains the specified number of most recent versions (default: 3)
- Removes old files: Deletes older versions to free disk space
- Updates manifest: Ensures manifest.json remains current
- Dry run option: Preview deletions without making changes
wheels assets clobber
Section titled “wheels assets clobber”Completely removes all compiled assets and the manifest file.
# Remove all compiled assets (with confirmation prompt)wheels assets clobber
# Skip confirmation promptwheels assets clobber --forceWhat it does
Section titled “What it does”- Deletes compiled directory: Removes
/public/assets/compiled/and all contents - Removes manifest: Deletes the manifest.json file
- Confirmation prompt: Asks for confirmation unless —force is used
- Complete cleanup: Useful for fresh starts or troubleshooting
Best Practices
Section titled “Best Practices”Production Deployment Workflow
Section titled “Production Deployment Workflow”- Before deployment:
# Compile assets for productionwheels assets precompile --environment=production
# Clean old versions to save spacewheels assets clean --keep=3- After deployment verification:
# If rollback needed, previous versions are still available# If deployment successful, further cleanup can be donewheels assets clean --keep=2Development Workflow
Section titled “Development Workflow”During development, you typically don’t need compiled assets:
# Remove all compiled assets in developmentwheels assets clobber --force
# Precompile only when testing production buildswheels assets precompile --environment=developmentContinuous Integration
Section titled “Continuous Integration”Example CI/CD pipeline step:
- name: Compile Assets run: | wheels assets precompile --environment=production wheels assets clean --keep=3File Structure
Section titled “File Structure”After running wheels assets precompile:
/public/ /assets/ /compiled/ manifest.json application-a1b2c3d4.min.js styles-e5f6g7h8.min.css logo-i9j0k1l2.png /javascripts/ application.js (original) /stylesheets/ styles.css (original) /images/ logo.png (original)Configuration
Section titled “Configuration”Configure asset handling in your Wheels application:
// Enable asset fingerprinting in productionset(useAssetFingerprinting = true);
// Set asset cache duration (in minutes)set(assetsCacheMinutes = 1440); // 24 hours
// Define assets pathset(assetsPath = "/assets");Troubleshooting
Section titled “Troubleshooting”Assets not updating in production
Section titled “Assets not updating in production”# Force recompilationwheels assets precompile --force
# Verify manifest exists and is currentcat public/assets/compiled/manifest.jsonDisk space issues
Section titled “Disk space issues”# Check space used by compiled assetsdu -sh public/assets/compiled/
# Aggressive cleanup - keep only 1 versionwheels assets clean --keep=1
# Or remove everything and recompilewheels assets clobber --forcewheels assets precompileMissing assets after deployment
Section titled “Missing assets after deployment”# Ensure assets were compiled for the correct environmentwheels assets precompile --environment=production
# Check that manifest.json existsls -la public/assets/compiled/manifest.json- Backup: Always backup assets before running
clobberin production - Version Control: Don’t commit compiled assets to version control
- Deployment: Run
precompileas part of your deployment process - Performance: Compiled assets significantly improve load times
- Cache Busting: Hash fingerprints ensure browsers load updated assets