Source Maps Utilities Php Library

Public Announcement of a new php library for working with source maps: koala-framework/sourcemaps

Source maps help with debugging minified javascript or css files, see the html5rocks article for a short introduction.

This library originated from koala framework where we support source maps created by sass and uglifyjs.

Features

  • creating mappings
  • reading mappings
  • source map aware string replace for existing mapping
  • concat maps (optimized for best performance)

Use cases

Concat into a single file

A common pattern is the creating of a single javascript and css file out of many source files for better performance (as the browser has to make less requests).This library allows concating multiple source maps and keeps the mappings intact.

During development performance is key, so we implemented this concat as performant as possible: we don't parse and write the whole mapping information, instead we only work with the strings and put them together - with an offset correction injected - so the maps stay intact.

String replacements

When different versions of a file need to be generated (eg. translation or replacing a base path) it makes sense to cache the uglifyjs compiled file and do required string replacements on that.

Example usage

//read
$map = new Kwf_SourceMaps_SourceMap($mapContents, $minimiedFileContents);
$map->getMappings()
 
//create new map
$map = Kwf_SourceMaps_SourceMap::createEmptyMap($minimiedFileContents);
$map->addMapping(2, 3, 10, 12, 'foo.js'); //$generatedLine, $generatedColumn, $originalLine, $originalColumn, $originalSource, $originalName = null)
$map->getMapContents();
 
//merge two maps
$map1->concat($map2);
 
//perform string replacement
$map->stringReplace('foo', 'bar');

Found any issue, bug or have a question? Create an issue on github.

This entry was posted in Koala Framework, Web Development by Niko Sams. Bookmark the permalink.

One Thought on "Source Maps Utilities Php Library"

[url=park82.ru]Автопрокат ПАРК[/url] предлагает бюджетные цены на [url=park82.ru/цены/]прокат автомобилей в Алуште[/url]. Качественные условия аренда на авто для путешествий в Алуште. В нашем прокате Вы можете арендовать автомобиль в Феодосии на выходные с кондиционером.

Leave a Reply

Your email address will not be published.

Github Activity

nsams merged a pull request in koala-framework/koala-framework

@nsams
nsams merged a pull request in koala-framework/koala-framework
Nov 20, 2017
deny access to welcome controller to normal users by default #638

Deny welcome contro lelr to normal users per default

+1 -0
1 comment

nsams pushed to 5.0 in koala-framework/koala-framework

@nsams
nsams pushed to 5.0 in koala-framework/koala-framework
Nov 20, 2017

nsams deleted branch symfony-kernel-getinstance at nsams/koala-framework

@nsams
nsams deleted branch symfony-kernel-getinstance at nsams/koala-framework
Nov 20, 2017

nsams pushed to 4.5 in koala-framework/koala-framework

@nsams
nsams pushed to 4.5 in koala-framework/koala-framework
Nov 20, 2017

nsams opened a pull request in koala-framework/koala-framework

@nsams
nsams opened a pull request in koala-framework/koala-framework
Nov 9, 2017
Add getInstance method for symfony kernel #640

this allows us using symfony services everywhere.

+14 -1