Symfony2 Assetic and Less Sourcemaps Symfony2 Assetic and Less Sourcemaps symfony symfony

Symfony2 Assetic and Less Sourcemaps


Yes, this is the right spot. However, you don't need to hack it. Extend it!

I use this:

# Using less source maps with Symfonynamespace Acme\MyBundle\Assetic;use Assetic\Asset\AssetInterface;class LessFilter extends AsseticLessFilter{    public function filterLoad(AssetInterface $asset)    {        $sourcemapRoot = realpath(dirname($asset->getSourceRoot() . '/' . $asset->getSourcePath()));        $this->addTreeOption('sourceMap', true);        $this->addTreeOption('sourceMapBasepath', $sourcemapRoot);        parent::filterLoad($asset);    }}// config.ymlassetic:    filters:        less:            class: Acme\MyBundle\Assetic\LessFilter

I found this snipped here:https://github.com/thomaswelton/blog/blob/master/articles/symfony/using-less-source-maps.md

It extends the Filters' filterLoad() method by adding two new tree parameters. All available tree parameters can be found here:

https://github.com/less/less.js/blob/master/bin/lessc#L361-L378

You gotta love dependency injection :)


Another way I've found to show the origin less file contents without faffing around with paths is to use the outputSourceFiles flag which bundles the less files into the generated css file (adds bloat so use in dev only).

<?php...class LessFilter extends AsseticLessFilter{    public function filterLoad(AssetInterface $asset)    {        $this->addTreeOption('sourceMap', true);        $this->addTreeOption('outputSourceFiles', true);        parent::filterLoad($asset);    }}