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.

2 Thoughts on "Source Maps Utilities Php Library"

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






















[url=][/url]
[url=][/url]
[url=][/url]
[url=][/url]


[url=][/url]
[url=][/url]
[url=][/url]
[url=][/url]


[url=][/url]
[url=][/url]
[url=][/url]
[url=][/url]


[url=][/url]
[url=][/url]
[url=][/url]

Leave a Reply

Your email address will not be published.

Github Activity

nsams commented on pull request koala-framework/koala-framework#673

@nsams
nsams commented on pull request koala-framework/koala-framework#673
Jan 4, 2018

Muss das konfigurierbar sein? Könnte ja immer gemacht werden, auch alle 1000 zb

nsams commented on pull request koala-framework/koala-framework#661

@nsams
nsams commented on pull request koala-framework/koala-framework#661
Jan 4, 2018

It was latin1 before. I'm not sure if that was intentional tough, probably to save space (as those logs might get huge)

nsams deleted branch kwcbem-replace at koala-framework/koala-framework

@nsams
nsams deleted branch kwcbem-replace at koala-framework/koala-framework
Jan 4, 2018

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

@nsams
nsams pushed to 5.0 in koala-framework/koala-framework
Jan 4, 2018

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

@nsams
nsams merged a pull request in koala-framework/koala-framework
Jan 4, 2018
+2 -1