Symfony2 Assetic和更少的Sourcemaps [英] Symfony2 Assetic and Less Sourcemaps
问题描述
我不确定如何破解资源少的过滤器以输出源地图文件.我在这里指的是LessFilter https://github. com/kriswallsmith/assetic/blob/master/src/Assetic/Filter/LessFilter.php
I am unsure how I can hack the assetic less filter to output a sourcemap file. I am referring to the LessFilter here https://github.com/kriswallsmith/assetic/blob/master/src/Assetic/Filter/LessFilter.php
第145和146行是创建Symfony\Component\Process\Process
对象的地方
$proc = $pb->getProcess();
$code = $proc->run();
麻烦的是,此输出被放置到一个文件中.我不确定如何生成第二个源地图文件.
The trouble is this output gets placed into one single file. I am not sure how to generate a second sourcemap file.
我如何扩展此过滤器或破解Assetic核心以使其正常工作?
How can I extend this filter or hack the Assetic core to make this work?
推荐答案
是的,这是正确的位置.但是,您无需对其进行破解.延长它!
Yes, this is the right spot. However, you don't need to hack it. Extend it!
我用这个:
# 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
I found this snipped here: https://github.com/thomaswelton/blog/blob/master/articles/symfony/using-less-source-maps.md
它通过添加两个新的树参数扩展了Filters的filterLoad()方法.所有可用的树参数都可以在这里找到:
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
您必须爱依赖注入:)
这篇关于Symfony2 Assetic和更少的Sourcemaps的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!