我正在开发我的第一个 Symfony 2 应用程序,我正在尝试使用 Uglify 来最小化我的 .css 文件。问题是当我执行命令时:
$ /Applications/mampstack-5.4.17-0/php/bin/php app/console assetic:dump --verbose
我得到以下结果:
Dumping all dev assets.
Debug mode is on.
17:22:09 [file+] /Users/bender22/Proyectos/ETraining/app/../web/examlayout.css
/Users/bender22/Proyectos/ETraining/app/../web/bundles/exam/css/exam.css
/Users/bender22/Proyectos/ETraining/app/../web/bundles/exam/css/exam3.css
[Symfony\Component\Process\Exception\RuntimeException]
该过程已用信号“5”发出信号。
异常跟踪:
() at /Users/bender22/Proyectos/ETraining/vendor/symfony/symfony/src/Symfony/Component/Process/Process.php:428
Symfony\Component\Process\Process->wait() at /Users/bender22/Proyectos/ETraining/vendor/symfony/symfony/src/Symfony/Component/Process/Process.php:204
Symfony\Component\Process\Process->run() at /Users/bender22/Proyectos/ETraining/vendor/kriswallsmith/assetic/src/Assetic/Filter/UglifyCssFilter.php:106
Assetic\Filter\UglifyCssFilter->filterDump() at /Users/bender22/Proyectos/ETraining/vendor/kriswallsmith/assetic/src/Assetic/Filter/FilterCollection.php:69
Assetic\Filter\FilterCollection->filterDump() at /Users/bender22/Proyectos/ETraining/vendor/kriswallsmith/assetic/src/Assetic/Asset/BaseAsset.php:108
Assetic\Asset\BaseAsset->dump() at /Users/bender22/Proyectos/ETraining/vendor/kriswallsmith/assetic/src/Assetic/Asset/AssetCollection.php:151
Assetic\Asset\AssetCollection->dump() at /Users/bender22/Proyectos/ETraining/vendor/symfony/assetic-bundle/Symfony/Bundle/AsseticBundle/Command/DumpCommand.php:222
Symfony\Bundle\AsseticBundle\Command\DumpCommand->doDump() at /Users/bender22/Proyectos/ETraining/vendor/symfony/assetic-bundle/Symfony/Bundle/AsseticBundle/Command/DumpCommand.php:162
Symfony\Bundle\AsseticBundle\Command\DumpCommand->dumpAsset() at /Users/bender22/Proyectos/ETraining/vendor/symfony/assetic-bundle/Symfony/Bundle/AsseticBundle/Command/DumpCommand.php:61
Symfony\Bundle\AsseticBundle\Command\DumpCommand->execute() at /Users/bender22/Proyectos/ETraining/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:244
Symfony\Component\Console\Command\Command->run() at /Users/bender22/Proyectos/ETraining/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:904
Symfony\Component\Console\Application->doRunCommand() at /Users/bender22/Proyectos/ETraining/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:191
Symfony\Component\Console\Application->doRun() at /Users/bender22/Proyectos/ETraining/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:85
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /Users/bender22/Proyectos/ETraining/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:121
Symfony\Component\Console\Application->run() at /Users/bender22/Proyectos/ETraining/app/console:27
我的环境:
OS: Mac OS 10.8.4
Symfony: 2.3.2
symfony/assetic-bundle: 2.3.0
kriswallsmith/assetic: 1.1.2
Bitnami Mampstack: 5.4.17
Node.js: 0.10.13
Php: 5.4.17
Apache: 2.4.4
以下是一些相关信息:
我的 config.yml:
assetic:
debug: %kernel.debug%
use_controller: false
bundles: [ExamBundle]
java: /usr/bin/java
filters:
cssrewrite: ~
uglifyjs2: # the path to the uglifyjs executable
bin: /usr/local/bin/uglifyjs
node: /usr/local/bin/node
uglifycss: # the path to the uglifycss executable
bin: /usr/local/bin/uglifycss
node: /usr/local/bin/node
我的 Twig 模板:
{% block stylesheets %}
{% stylesheets output='css/generated/examlayout.css' filter='cssrewrite, uglifycss' debug=false
'bundles/exam/css/exam.css'
'bundles/exam/css/exam3.css'
%}
<link href="{{ asset_url }}" rel="stylesheet" />
{% endstylesheets %}
{% endblock %}
我已经测试过的一些东西没有运气:
1)执行命令(不指定/Applications/mampstack-5.4.17-0/php/bin/php )
$ app/console assetic:dump --verbose
结果是
Dumping all dev assets.
Debug mode is on.
17:55:12 [file+] /Users/bender22/Proyectos/ETraining/app/../web/css/generated/examlayout.css
/Users/bender22/Proyectos/ETraining/app/../web/bundles/exam/css/exam.css
/Users/bender22/Proyectos/ETraining/app/../web/bundles/exam/css/exam3.css
web/css 中的结果文件是正确的(内容包括最小化的 .css 文件)。问题是当我加载网页时,.css 损坏了:
<link href="/app_dev.php/css/generated/examlayout.css" rel="stylesheet" />
如果我点击 href,浏览器显示的内容是:
/*
[exception] 500 | Internal Server Error | Symfony\Component\Process\Exception\RuntimeException
[message] The process has been signaled with signal "5".
[1] Symfony\Component\Process\Exception\RuntimeException: The process has been signaled with
signal "5".
at n/a
in /Users/bender22/Proyectos/ETraining/vendor/symfony/symfony/src/Symfony/Component/Process
/Process.php line 428
at Symfony\Component\Process\Process->wait(null)
in /Users/bender22/Proyectos/ETraining/vendor/symfony/symfony/src/Symfony/Component/Process
/Process.php line 204
at Symfony\Component\Process\Process->run()
in /Users/bender22/Proyectos/ETraining/vendor/kriswallsmith/assetic/src/Assetic/Filter
/UglifyCssFilter.php line 106
at Assetic\Filter\UglifyCssFilter->filterDump(object(FileAsset))
in /Users/bender22/Proyectos/ETraining/vendor/kriswallsmith/assetic/src/Assetic/Filter
/FilterCollection.php line 69
at Assetic\Filter\FilterCollection->filterDump(object(FileAsset))
in /Users/bender22/Proyectos/ETraining/vendor/kriswallsmith/assetic/src/Assetic/Asset
/BaseAsset.php line 108
at Assetic\Asset\BaseAsset->dump(null)
in /Users/bender22/Proyectos/ETraining/vendor/kriswallsmith/assetic/src/Assetic/Asset
/AssetCollection.php line 151
at Assetic\Asset\AssetCollection->dump(null)
in /Users/bender22/Proyectos/ETraining/vendor/kriswallsmith/assetic/src/Assetic/Asset
/AssetCache.php line 69
at Assetic\Asset\AssetCache->dump()
in /Users/bender22/Proyectos/ETraining/vendor/symfony/assetic-bundle/Symfony/Bundle
/AsseticBundle/Controller/AsseticController.php line 88
at Symfony\Bundle\AsseticBundle\Controller\AsseticController->render('6a1dad3',
null)
in line
at call_user_func_array(array(object(AsseticController), 'render'),
array('6a1dad3', null))
in /Users/bender22/Proyectos/ETraining/app/bootstrap.php.cache line 2774
at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), '1')
in /Users/bender22/Proyectos/ETraining/app/bootstrap.php.cache line 2748
at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), '1', true)
in /Users/bender22/Proyectos/ETraining/app/bootstrap.php.cache line 2878
at Symfony\Component\HttpKernel\DependencyInjection
\ContainerAwareHttpKernel->handle(object(Request), '1', true)
in /Users/bender22/Proyectos/ETraining/app/bootstrap.php.cache line 2179
at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
in /Users/bender22/Proyectos/ETraining/web/app_dev.php line 28
*/
2)设置文件夹权限(以递归方式):
chmod 777
对于文件夹:
web(在我的 Symfony 元素中)和我的临时文件夹,结果是:
/var/folders/hp/vv24wsq56bs9szlt7j8bt3600000gn/T
你能帮我解决这个问题吗?我已经没有想法了。
注意:我将其标记为 uglifyjs2 因为我没有足够的点数来创建标记 uglifycss
提前致谢 :)
最佳答案
我们遇到了同样的问题,即 uglifycss 过滤器因大 css 文件耗尽内存而没有正确的错误消息。
您可以按照以下步骤显示确切的错误消息:
assetic:dump
任务 uglifycss <filename> > test.css
我们通过覆盖 UglifyCssFilter 类并添加自定义 Node.js 参数以提高内存限制来解决我们的问题:
<?php
namespace Acme\DemoBundle\Filter;
use Assetic\Filter\UglifyCssFilter as BaseUglifyCssFilter;
class UglifyCssFilter extends BaseUglifyCssFilter
{
protected function createProcessBuilder(array $arguments = array())
{
if ($arguments[0] === '/usr/bin/node') {
$arguments = array_merge(array(
$arguments[0],
'--max-old-space-size=4096'
), array_slice($arguments, 1));
}
return parent::createProcessBuilder($arguments);
}
}
您必须将节点路径更改为正确的位置(或以其他方式改进比较)。
您可以通过在配置文件中设置服务参数来让 Assetic 使用此类:
parameters:
assetic.filter.uglifycss.class: Acme\DemoBundle\Filter\UglifyCssFilter