2012-04-24 112 views
1

我想使用YUI壓縮機minify PHP而不是默認的JSmin。有沒有人有經驗設置這個?如何使用YUI壓縮器來縮小PHP?

現在我正在使用groupsConfig.php來組合JS。

return array(
    'jsAll' => array('//contenido/themes/bam/assets/js/jquery.js', '//contenido/themes/bam/assets/js/modernizr.js','//contenido/themes/bam/assets/js/imgpreload.js', '//contenido/themes/bam/assets/js/imgpreload.js', '//contenido/themes/bam/assets/js/history.js','//contenido/themes/bam/assets/js/ajaxify.js', '//contenido/themes/bam/assets/js/isotope.js'), 
    'jsHome' => array('//contenido/themes/bam/assets/js/easing.js','//contenido/themes/bam/assets/js/scrollable.js', '//contenido/themes/bam/assets/js/home.js'), 
    'cssAll' => array('//contenido/themes/bam/bam.css'), 
); 

由於it says on the homepage

用途道格拉斯Crockford的JSMin庫和自定義類的增強端口來縮小CSS和HTML

我在config.php下面的代碼,但當試圖查看組合的js文件時,出現500錯誤:

function yuiJs($js) { 
    require_once '/lib/Minify/YUICompressor.php'; 
    Minify_YUICompressor::$jarFile = '/lib/yuicompressor-2.4.2.jar'; 
    Minify_YUICompressor::$tempDir = '/temp'; 
    return Minify_YUICompressor::minifyJs($js); 
} 
$min_serveOptions['minifiers']['application/x-javascript'] = 'yuiJs'; 

它也似乎有幾行的lib /縮減大小/ YUICompressor.php需要進行配置,我不知道我在做正確的事:

class Minify_YUICompressor { 

    /** 
    * Filepath of the YUI Compressor jar file. This must be set before 
    * calling minifyJs() or minifyCss(). 
    * 
    * @var string 
    */ 
    public static $jarFile = '../yuicompressor-2.4.2.jar'; 

    /** 
    * Writable temp directory. This must be set before calling minifyJs() 
    * or minifyCss(). 
    * 
    * @var string 
    */ 
    public static $tempDir = '../../temp/'; 

    /** 
    * Filepath of "java" executable (may be needed if not in shell's PATH) 
    * 
    * @var string 
    */ 
    public static $javaExecutable = 'java'; 
+0

默認jsmin? jsmin默認在哪裏? YUI壓縮機的使用記錄在供應商主頁上:http://developer.yahoo.com/yui/compressor/ – hakre 2012-04-24 06:42:46

+0

我修改了我的問題以澄清 – 2012-04-24 06:48:47

回答

0

我有同樣的問題在窗戶上。看來jar文件需要可執行才能運行yui壓縮器。所以,我必須從YUICompressor.php

#132 


private static function _prepare() 
    { 
     if (! is_file(self::$jarFile)) { 
      throw new Exception('Minify_YUICompressor : $jarFile('.self::$jarFile.') is not a valid file.'); 
     } 
//   if (! is_executable(self::$jarFile)) { 
//    throw new Exception('Minify_YUICompressor : $jarFile('.self::$jarFile.') is not executable.'); 
//   } 
     if (! is_dir(self::$tempDir)) { 
      throw new Exception('Minify_YUICompressor : $tempDir('.self::$tempDir.') is not a valid direcotry.'); 
     } 
     if (! is_writable(self::$tempDir)) { 
      throw new Exception('Minify_YUICompressor : $tempDir('.self::$tempDir.') is not writable.'); 
     } 
    } 

刪除excutable檢查和工作正常。