class AppAsset extends AssetBundle
{
public $sourcePath = '@common/assets/css';
public $css = [
'styles.less',
'foo.bar',
'hello.css',
];
}'assetManager' => [
'converter' => [
'class' => yii\web\AssetConverter::className(),
'commands' => [
'bar' => ['css', 'lessc {from} {to} --clean-css'],
'less' => ['css', 'lessc {from} {to} --clean-css --no-color'],
],
],
],'assetManager' => [
'converter' => [
'class' => yii\web\AssetConverter::className(),
'commands' => [
'css' => ['css', 'lessc {from} {to} --clean-css'], // добавим это
'bar' => ['css', 'lessc {from} {to} --clean-css'],
'less' => ['css', 'lessc {from} {to} --clean-css --no-color'],
],
],
],/**
* Converts a given asset file into a CSS or JS file.
* @param string $asset the asset file path, relative to $basePath
* @param string $basePath the directory the $asset is relative to.
* @return string the converted asset file path, relative to $basePath.
*/
public function convert($asset, $basePath)
{
$pos = strrpos($asset, '.');
if ($pos !== false) {
$ext = substr($asset, $pos + 1);
if (isset($this->commands[$ext])) {
list ($ext, $command) = $this->commands[$ext];
$result = substr($asset, 0, $pos + 1) . $ext;
// все дело в этой проверке
// |||||||||||||||||||||||||||||||||||||||||||
// VVVVVVVVVVVVVVVVVV
if ($this->forceConvert || @filemtime("$basePath/$result") < @filemtime("$basePath/$asset")) {
$this->runCommand($command, $basePath, $asset, $result);
}
return $result;
}
}
return $asset;
}foo.bar, то файл foo.bar копируется в assets с таким же именем. Затем, согласно $commands в AssetConverter, имя должно смениться на foo.css. А так как у нас пока еще foo.css не существует, то и filemtime('foo.css') = false, и если forceConvert = false, а ставить его в true имеет мало смысла, тогда и происходит запуск runCommand().hello.css, он попадает в assets уже с расширением css, и если сравнить filemtime сорца и результата, то они будут равны, и никакой магии не произойдёт.