2
讓我開始說我完全不知道應該做什麼,因爲有關Assetic的文檔和可用信息是有限的或面向Symfony的。在Symfony以外使用Assetic的Css重寫器
這是我的文件夾結構。
Assetic
+ assets
+ css
+ example.css
+ docs
+ src
+ tests
+ vendor
+ index.php
+ styles.php
現在,我有以下測試代碼。基本上我克隆了一個乾淨的副本資產和運行composer install
。然後我創建一個index.php
文件,該文件只需鏈接到我的styles.php
文件和HTML標記<link>
標記。
這裏是我的styles.php
<?php
require 'vendor/autoload.php';
$assetPath = __DIR__.'/assets/css/example.css';
$assetBasePath = __DIR__.'/assets/css';
$asset = new Assetic\Asset\FileAsset($assetPath, array(), $assetBasePath, 'example.css');
header('Content-Type: text/css');
$asset->setTargetPath(__DIR__);
echo $asset->dump(new Assetic\Filter\CssRewriteFilter);
這是我example.css
樣式表。
body {
background-image: url('../img/background.png');
}
當我在我的瀏覽器中加載styles.php
時,我得到以下輸出。
url('../img/background.png');
這與實際的CSS相同。如果我使用Clay先生的CSS URI重寫器,我會得到預期的輸出結果。
url('/Assetic/assets/img/background.png');
那麼,我在做什麼錯誤的資產?我不知道我應該傳遞什麼路徑到哪裏。
謝謝。
我仍然無法使它工作。目標路徑,您的意思是絕對路徑或URL。從查看Assetic的來源,它似乎要求提供資產目標的URL。 –
我把dirname($ assetPath)放在哪裏,它應該是包含css文件的目錄的絕對路徑。 '/ assets/css'是資產目錄的URL。 $ asset-> setTargetPath('/ path/to/dumped/asset');這裏是包含轉儲資產的目錄的絕對路徑。 – chadrien