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/kwc-newsletter#5

@nsams
nsams commented on pull request koala-framework/kwc-newsletter#5
Feb 22, 2018

bitte um abstimmung bin benjamin damit die bundles gleich strukturiert sind https://gitlab.vivid-planet.com/vivid/kwf-carlog-auth

nsams commented on issue koala-framework/koala-framework#736

@nsams
Feb 20, 2018

Yes, that is the correct fix, ajax requests timeout after 30 seconds by default. Now why the request is that slow is a completely different topic, …

nsams starred ionic-team/stencil

@nsams
Feb 19, 2018
ionic-team/stencil

A simple, reusable web component compiler

TypeScript 2.3k 5 issues need help Updated Feb 19

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

@nsams
nsams commented on pull request koala-framework/koala-framework#728
Feb 15, 2018

des funktioniert dann nicht mehr

nsams commented on pull request koala-framework/kwc-newsletter#2

@nsams
nsams commented on pull request koala-framework/kwc-newsletter#2
Feb 15, 2018

bitte da keine leerzeile