我不确定如何破解 assetic less 过滤器来输出 sourcemap 文件。我在这里指的是 LessFilter https://github.com/kriswallsmith/assetic/blob/master/src/Assetic/Filter/LessFilter.php
lines 145 and 146是创建Symfony\Component\Process\Process
对象的地方
$proc = $pb->getProcess();
$code = $proc->run();
问题是这个输出被放在一个文件中。我不确定如何生成第二个源映射文件。
我如何扩展此过滤器或破解 Assetic 核心以使其正常工作?
最佳答案
是的,这是正确的地方。但是,您不需要破解它。扩展它!
我用这个:
# 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
你一定喜欢依赖注入(inject):)
关于php - Symfony2 Assetic 和 Less Sourcemaps,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24255882/