gpt4 book ai didi

twitter-bootstrap - 从 less 在 yii2 中编译自定义 Bootstrap css

转载 作者:行者123 更新时间:2023-12-04 02:22:26 24 4
gpt4 key购买 nike

我正在使用 Yii2 和 Composer 开始一个新项目(在使用 YII 1 完成几个项目之后)。

我用 composer 创建了一个新的“高级项目”。一切都很好,但是,我想知道自定义 Bootstrap 主题的最佳方法是什么?

我认为将整个 Bootstrap 较少地复制到后端和前端并编辑两个变量文件并编译它不是正确的方法。

那么:是否有可能以某种方式扩展 Composer 下载的 less 文件并仅编辑这两个变量文件?

最佳答案

Bootstrap 配置可以通过更改 variables.less 来完成。下面的 BootstrapAsset 是原来的替代品,它使用当前目录中的 bootstrap-variables.less 而不是原来的 variables.less。

namespace app\assets;

use yii\helpers\FileHelper;
use yii\web\AssetBundle;

class BootstrapAsset extends AssetBundle
{
public $sourcePath = '@bower/bootstrap/dist';
public $css = [
'css/bootstrap.css',
];

public function publish($am)
{
if ($this->sourcePath !== null && !isset($this->basePath, $this->baseUrl)) {
list ($this->basePath, $this->baseUrl) = $am->publish($this->sourcePath, $this->publishOptions);
}

$src = \Yii::getAlias($this->sourcePath);

FileHelper::copyDirectory("$src/../less", $this->basePath."/less");

$vars = file_get_contents(__DIR__ . "/bootstrap-variables.less");
$css = \Yii::$app->cache->get("bootstrap-css-".crc32($vars));
if (!$css)
{
file_put_contents("$src/../less/variables.less", $vars);

ini_set('xdebug.max_nesting_level', 200);

$less = new \lessc();
$less->setFormatter(YII_DEBUG ? "lessjs" : "compressed");
unlink($this->basePath . "/css/bootstrap.css");
$less->compileFile("$src/../less/bootstrap.less", $this->basePath . "/css/bootstrap.css");
\Yii::$app->cache->set("bootstrap-css-".crc32($vars), file_get_contents($this->basePath . "/css/bootstrap.css"));
}
else
{
file_put_contents($this->basePath . "/css/bootstrap.css", $css);
}
}
}

关于twitter-bootstrap - 从 less 在 yii2 中编译自定义 Bootstrap css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27045361/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com