1

我想使用 YUI 压缩器来缩小 PHP而不是默认的 JSmin。有没有人有设置这个的经验?

现在我正在使用 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'),
);

正如主页上所说

使用 Douglas 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/Minify/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';
4

1 回答 1

0

我在 Windows 上遇到了同样的问题。似乎 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.');
        }
    }

这很好用。

于 2013-01-03T06:36:47.237 回答