Symfony2 Assetic and Less Sourcemaps

I'm not sure how I can crack the assetic less filter to output the sourcemap file. I mean LessFilter here https://github.com/kriswallsmith/assetic/blob/master/src/Assetic/Filter/LessFilter.php

lines 145 and 146 are an object Symfony\Component\Process\Processcreated

  $proc = $pb->getProcess();
  $code = $proc->run();

The problem is that this output is placed in a single file. I am not sure how to create a second sourcemap file.

How can I expand this filter or hack Assetic core to do this?

+4
source share
2 answers

Yes, this is a suitable place. However, you do not need to hack it. Expand it!

I use this:

# Using less source maps with Symfony
namespace 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.yml
assetic:
    filters:
        less:
            class: Acme\MyBundle\Assetic\LessFilter

, : https://github.com/thomaswelton/blog/blob/master/articles/symfony/using-less-source-maps.md

filterLoad() . :

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

:)

+5

, , , , outputSourceFiles, css ( , dev).

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

        parent::filterLoad($asset);
    }
}
0

Source: https://habr.com/ru/post/1544846/


All Articles