axy/sourcemap
PHP library to create, load, search, and modify Source Map files. Supports renaming/removing sources, adjusting mappings, handling insert/remove blocks, concatenating maps for concatenated outputs, and merging intermediate maps. Works with maps only, not source/output code.
debugbar) to map stack traces back to original source files.laravel-mix-sourcemaps or vite-plugin-laravel for enhanced source map handling.$this->app->singleton(SourceMapManager::class, function ($app) {
return new SourceMapManager(base_path('source-maps'));
});
php artisan sourcemap:merge).Artisan::command('sourcemap:merge', function () {
$map = SourceMap::loadFromFile(storage_path('app/intermediate.map'));
$map->merge(storage_path('app/original.map'));
$map->save(storage_path('app/merged.map'));
});
| Risk Area | Mitigation Strategy |
|---|---|
| Source Map Version Support | Test with V3 (most widely used) and V4 (emerging). Fallback to V3 if needed. |
| File Path Resolution | Use Laravel’s storage_path(), public_path() helpers to avoid hardcoded paths. |
| Concurrency in CI/CD | Ensure thread-safe file operations (e.g., lock files during merges). |
| Performance for Large Maps | Benchmark with 10K+ line source maps; optimize if find() operations are slow. |
| Backward Compatibility | Version package explicitly (e.g., "axy/sourcemap": "^1.0"). |
Build Tool Strategy:
axy/sourcemap for post-processing (e.g., merging vendor + app source maps).Debugging Workflow:
debugbar or laravel-debugbar for stack trace mapping?SourceMapResolver middleware to translate errors to original source files.CI/CD Pipeline:
deploy.php) or manual (e.g., via Artisan)?deploy:post hook.User Experience:
Testing Scope:
| Laravel Component | Integration Point | Example Use Case |
|---|---|---|
| Laravel Mix/Vite | Post-process source maps after compilation. | Merge vendor/source maps into a single .map file for debugging. |
| Artisan | CLI commands for manual source map operations. | php artisan sourcemap:concat app.js vendor.js |
| Service Container | Register SourceMapManager as a singleton. |
Inject into controllers for dynamic source map generation. |
| Debugging Tools | Extend debugbar to display original source code via source maps. |
Click on stack trace lines to jump to original .ts/.js files. |
| Storage System | Store source maps in storage/app/source-maps/. |
Organize by environment (e.g., source-maps/production/, source-maps/local/). |
| Event System | Listen to Compiled events to trigger source map merging. |
Automatically merge source maps after mix build or vite build. |
Phase 1: Proof of Concept (2 weeks)
axy/sourcemap into a single Laravel project (e.g., a monorepo with Mix/Vite).source-map npm package).Phase 2: Core Integration (3 weeks)
laravel-sourcemap) wrapping axy/sourcemap.Phase 3: Ecosystem Adoption (Ongoing)
| Compatibility Check | Status | Notes |
|---|---|---|
| Laravel 9+ (PHP 8.1+) | ✅ Supported | No breaking changes expected. |
| Laravel Mix/Vite | ✅ Plug-and-Play | Post-process source maps via mix.after() or Vite hooks. |
| Node.js Source Maps (V3/V4) | ✅ Full Support | Test with TypeScript, Babel, and Webpack source maps. |
| Custom Build Tools | ⚠️ Manual Integration | Requires custom logic for non-standard source map formats. |
| Windows/Linux/MacOS | ✅ Cross-Platform | File path handling abstracted via Laravel helpers. |
composer require axy/sourcemap
.env:
SOURCE_MAPS_PATH=storage/app/source-maps
config/app.php:
'providers' => [
// ...
axy\sourcemap\Laravel\ServiceProvider::class,
],
php artisan vendor:publish --provider="axy\sourcemap\Laravel\ServiceProvider"
// vite.config.js
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import { mergeSourceMaps } from 'laravel-sourcemap';
export default defineConfig({
plugins: [
laravel({
input: ['resources/js/app.js'],
refresh: true,
}),
],
build: {
onEnd: async () => {
await mergeSourceMaps([
'dist/assets/app.js.map',
'dist/assets/vendor.js.map',
]);
},
},
});
axy/sourcemap for breaking changes (MIT license allows forks if needed).How can I help you explore Laravel packages today?