Created
October 28, 2025 17:51
-
-
Save Maxiviper117/55f92dc2b620d9ccd746f54acb7b9d61 to your computer and use it in GitHub Desktop.
FastComposerDump.ps1 – Speed Up Composer Autoload Generation for Laravel Projects on Windows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <# | |
| FastComposerDump.ps1 | |
| IMPORTANT: Run this script as Administrator. | |
| This script temporarily adds your project directory to Windows Defender exclusions to speed up Composer autoload generation, then removes the exclusion after completion. | |
| Usage: | |
| - Right-click PowerShell and select "Run as administrator" | |
| - Execute the script: | |
| .\FastComposerDump.ps1 -ProjectPath "C:\path\to\project" -ComposerArgs "dump-autoload --optimize" | |
| #> | |
| param( | |
| [string]$ProjectPath = (Get-Location).Path, | |
| [string]$ComposerArgs = "dump-autoload" # Optional: Customize Composer command, e.g., "dump-autoload --optimize" | |
| ) | |
| # Function to add exclusion | |
| function Add-Exclusion { | |
| param([string]$Path) | |
| try { | |
| Add-MpPreference -ExclusionPath $Path | |
| Write-Host "Added exclusion for: $Path" -ForegroundColor Green | |
| } catch { | |
| Write-Warning "Failed to add exclusion (may already exist or insufficient permissions): $($_.Exception.Message)" | |
| } | |
| } | |
| # Function to remove exclusion | |
| function Remove-Exclusion { | |
| param([string]$Path) | |
| try { | |
| Remove-MpPreference -ExclusionPath $Path | |
| Write-Host "Removed exclusion for: $Path" -ForegroundColor Green | |
| } catch { | |
| Write-Warning "Exclusion removal failed (may not have been present): $($_.Exception.Message)" | |
| } | |
| } | |
| # Main execution | |
| Write-Host "Starting fast Composer dump for: $ProjectPath" -ForegroundColor Cyan | |
| Add-Exclusion -Path $ProjectPath | |
| Write-Host "Running: composer $ComposerArgs" -ForegroundColor Yellow | |
| $argList = $ComposerArgs -split ' ' | |
| & cmd /c "composer $ComposerArgs" | |
| if ($LASTEXITCODE -eq 0) { | |
| Write-Host "Composer completed successfully!" -ForegroundColor Green | |
| } else { | |
| Write-Warning "Composer exited with code $LASTEXITCODE" | |
| } | |
| Remove-Exclusion -Path $ProjectPath | |
| Write-Host "Workflow complete!" -ForegroundColor Cyan |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment