matthiasmullie/path-converter
Convert relative paths between source and target locations. Given a file currently relative to one path (e.g., an import), it returns the equivalent relative path from another path—useful for moving/minifying assets while keeping URLs correct.
Asset Optimization & Build Pipelines:
resources/ → public/).url() references in CSS/JS during minification or bundling without manual edits.dev/ vs. prod/).Content Management & Dynamic File Handling:
Legacy System Modernization:
Cross-Platform & Testing:
Build vs. Buy:
../, ., or OS-specific separators).str_replace()) require more code and less robustness.url() or import references when files move.../../ or Windows paths).path in Node.js.http:// to relative paths).Finder or Laravel’s Storage facade).\), requiring pre-processing (though the package can handle it with normalization).*"This package eliminates a hidden technical debt in our file management and asset pipelines. By adopting matthiasmullie/path-converter, we can:
*"This is a drop-in solution for converting relative paths between directories—critical for:
url() references when moving files (e.g., resources/ → public/).../../, .) out of the box.composer.json:
composer require matthiasmullie/path-converter
str_replace() calls with:
$converter = new Converter('/old/base', '/new/base');
$fixedPath = $converter->convert('../../file.txt'); // Returns '../file.txt'
str_replace('\\', '/', $path)).
Alternatives (e.g., str_replace()) are less robust and require more code. This is a safe, proven choice."**"Need to fix paths when moving files? This package does it automatically and correctly. Here’s how to use it:
// Convert paths from `/src/assets` to `/public/dist`
$converter = new Converter('/src/assets', '/public/dist');
$cssPath = $converter->convert('../../images/logo.png');
// Output: '../images/logo.png' (relative to `/public/dist`)
Use cases:
url() references in compiled CSS/JS.storage/app/uploads.../../ → ../. → (removes)/ and \ (if normalized).
Just add it to composer.json—no framework lock-in!"*How can I help you explore Laravel packages today?