4
我試圖將所有使用的css文件合併爲一個。但是包含相對路徑的資源會導致問題。我試過資產的CssRewriteFilter,但它不起作用。CssRewrite過濾器不會將相對url轉換爲絕對
這裏是我的代碼:
$files = [
'/node_modules/select2/dist/css/select2.min.css',
'/node_modules/jquery-datetimepicker/jquery.datetimepicker.css',
'/node_modules/icheck/skins/square/blue.css',
'/node_modules/Plupload/js/jquery.plupload.queue/css/jquery.plupload.queue.css',
'/node_modules/pace/themes/white/pace-theme-flash.css',
'/node_modules/lightgallery/dist/css/lightgallery.min.css',
'/node_modules/x-editable/dist/bootstrap3-editable/css/bootstrap-editable.css',
'/node_modules/sweetalert2/dist/sweetalert2.css',
'/node_modules/animate.css/animate.min.css',
'/node_modules/fullcalendar/dist/fullcalendar.min.css',
'/node_modules/flag-icon-css/css/flag-icon.min.css',
'/theme/assets/skin/default_skin/css/theme.css',
];
$am = new \Assetic\AssetManager();
$items = [];
foreach ($files as $file) {
$filename = APP_ROOT_DIR . '/public/ui' . $file;
$items[] = new \Assetic\Asset\FileAsset($filename, [new \Assetic\Filter\CssRewriteFilter()]);
}
$collection = new \Assetic\Asset\AssetCollection(
$items
);
$collection->setTargetPath('vendor.css');
$am->set('collection', $collection);
$writer = new \Assetic\AssetWriter(APP_ROOT_DIR . '/public/ui/shared/css/');
$writer->writeManagerAssets($am);
我期待什麼:
當IMG是/node_modules/test/css/test.css
包含../img/test.png
代碼Assetic應該把它改寫爲/node_modules/test/img/test.png
你不是混亂$ sourceRoot (第三個參數)與$ sourcePath(第四個參數)。再次檢查鏈接中的代碼。你實際上正在複製功能。 – Phil