- How can I use axy/sourcemap with Laravel Mix or Vite for source map merging?
- axy/sourcemap integrates seamlessly with Laravel Mix or Vite by processing source maps post-compilation. After your build step, use the `SourceMap::loadFromFile()` method to load intermediate maps, then call `merge()` or `concatenate()` to combine them. Save the result to a single `.map` file for debugging. Example: `SourceMap::load('app.map')->merge('vendor.map')->save('final.map')`.
- Does axy/sourcemap support Laravel 9+ and PHP 8.1+?
- Yes, axy/sourcemap is fully compatible with Laravel 9+ and PHP 8.1+. The package has no breaking changes and is optimized for modern Laravel ecosystems. Tested with Laravel Mix/Vite and debug tools like Laravel Debugbar. Always pin to a specific version (e.g., `^1.0`) in `composer.json` for stability.
- Can I rename or remove sources in a source map file using this package?
- Absolutely. axy/sourcemap provides methods like `renameSource()` and `removeSource()` to modify source entries in a map file. This is useful for reorganizing assets (e.g., moving vendor sources to a separate directory) or cleaning up unused files. Example: `$map->renameSource('old.js', 'new.js')` or `$map->removeSource('unused.css')`.
- How do I handle insert/remove blocks in generated content with source maps?
- Use the `insertBlock()` and `removeBlock()` methods to adjust source map positions when content is added or removed during builds. For example, if you insert a chunk of code at line 10, call `$map->insertBlock(10, $newMappings)`. This ensures generated line numbers remain accurate. Works with Laravel Mix/Vite concatenation or manual asset manipulation.
- Is axy/sourcemap suitable for CI/CD pipelines where source maps are generated dynamically?
- Yes, the package is stateless and optimized for CI/CD. Process source maps during build steps (e.g., in a deploy script) and merge intermediate files into a single map. Use thread-safe file operations (e.g., lock files) to avoid conflicts. Example: Merge vendor and app maps in a `deploy:post` hook using Artisan commands or a service provider.
- How can I integrate axy/sourcemap with Laravel Debugbar for stack trace mapping?
- Extend Laravel Debugbar by creating a `SourceMapResolver` middleware or service. Inject the `SourceMapManager` into your debugbar configuration to translate error stack traces back to original source files. Example: Register the manager in `AppServiceProvider` and use it to resolve line numbers via `$manager->findOriginalPosition($generatedLine)`. Clickable links in debugbar can then jump to original `.ts`/`.js` files.
- What are the performance implications for large source maps (e.g., 10K+ lines)?
- axy/sourcemap is optimized for performance, but large maps may impact `find()` operations. Benchmark with your specific use case; if slow, consider pre-processing maps or caching results. The package avoids heavy dependencies and defers processing to build time, ensuring zero runtime overhead. Test with your largest map to validate performance.
- Can I use axy/sourcemap to concatenate source maps for bundled assets?
- Yes, the `concatenate()` method merges multiple source maps into one, ideal for bundled assets (e.g., combining `app.js` and `vendor.js` maps). This is useful in Laravel Mix/Vite when concatenating files. Example: `$mergedMap = SourceMap::concatenate([$map1, $map2])->save('bundle.map')`. Supports both V3 and V4 formats.
- Are there alternatives to axy/sourcemap for Laravel source map handling?
- For Laravel, alternatives include built-in Laravel Mix/Vite source map tools or plugins like `laravel-mix-sourcemaps`. However, axy/sourcemap offers deeper manipulation (e.g., renaming sources, handling insert/remove blocks) and is more flexible for custom workflows. Use it as a complementary layer when built-in tools lack advanced features like merging intermediate maps.
- How do I test source map functionality in my Laravel application?
- Test by creating a `SourceMap` instance, loading a sample map, and verifying operations like `find()`, `renameSource()`, or `merge()`. Use PHPUnit to assert mappings. Example: `$map = SourceMap::loadFromFile('test.map'); $this->assertEquals(['line' => 10], $map->find(50));`. Include edge cases like malformed maps or circular dependencies. The package’s docs cover supported formats (V3/V4) and error handling.