2012-04-24 114 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检查和工作正常。