Windows 上的 symfony2 assetics yui 压缩器(路径语法)

发布于 2024-12-17 00:03:55 字数 1038 浏览 0 评论 0原文

我正在尝试让 assetics 与 yui 压缩器一起运行,如果正在运行,则使用 sass。目前,两者都不起作用。当从 config.yml 和 twig 模板中删除所有过滤器时,它可以工作,并且 php app/console assetic:dump 会复制 css 和 js 文件。

现在我想添加 yui 压缩器,我的 config.yml 如下所示:

assetic:
  debug: %kernel.debug%
  use_controller: false
  filters:
    yui_js:
      jar: %kernel.root_dir%/Resources/java/yuicompressor-2.4.6.jar

将过滤器添加到模板并再次运行 assetic:dump 会出现以下错误(我翻译的消息):

[RuntimeException]
The syntax for filename, directory name or drive name is wrong

我发现 一篇文章告诉我指定java.exe 的路径,所以我将其添加到 config.yml 中:

assetic:
  ..
  java: C:/Program Files (x86)/Java/jre6/bin/java.exe
  ..

现在 assetic:dump 告诉我:

[RuntimeException]
The COMMAND "C:/Program" is either written wrong or

我尝试使用这两个变量(使用 \ 或 \ 而不是 /,添加单引号或双引号,使用短别名 Progra~ 1 或 Progra~2) 在配置中,但我没有得到任何结果。这两个错误总是出现。也许有人可以指出我正确的方向。

I'm trying to get assetics running with the yui compressor and, if this is running, sass. Right now, both don't work. When removing all filters from config.yml and the twig template, it works and php app/console assetic:dump does copy the css and js files.

Now I want to add the yui compressor and my config.yml looks like this:

assetic:
  debug: %kernel.debug%
  use_controller: false
  filters:
    yui_js:
      jar: %kernel.root_dir%/Resources/java/yuicompressor-2.4.6.jar

Adding the filter to the template and running assetic:dump again ends in the following error (translation of message by me):

[RuntimeException]
The syntax for filename, directory name or drive name is wrong

I found an article telling me to specify the path to java.exe, so I add this to config.yml:

assetic:
  ..
  java: C:/Program Files (x86)/Java/jre6/bin/java.exe
  ..

Now assetic:dump tells me:

[RuntimeException]
The COMMAND "C:/Program" is either written wrong or

I tried playing around with both variables (using \ or \ instead of /, adding single or double quotes, working with short alias Progra~1 or Progra~2) in the config, but I didn't get anywhere. The both errors comming up all the time. Maybe someone can point me in the right direction.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情独悲 2024-12-24 00:03:55

好吧,我明白了。伙计,这太残酷了。

让我们从简单的事情开始。 config.yml 的工作版本可能如下所示:

assetic:
  debug: false
  use_controller: false
  java: C:\Program Files (x86)\Java\jre6\bin\java.exe
  sass: C:\Program Files (x86)\Ruby192\bin\sass.bat
  filters:
    scss: ~
    yui_js:
      jar: %kernel.root_dir%\Resources\java\yuicompressor-2.4.6.jar

出于某种原因,assetic 总是导入 scss 的整个目录,因此我必须创建一个 merge.scss,它以正确的顺序导入其他 scss 文件。

现在它变得丑陋了,因为人们必须改变资产核心才能使其发挥作用。 assetic 的开发人员知道这个错误,我认为它已在某些开发主干/分支中修复,但不是稳定的。

Assetic\Util\ProcessBuilder 必须在第 95 行

if (defined('PHP_WINDOWS_VERSION_MAJOR')) {

、第 103 行

$script .= ' '.implode(' ', array_map('escapeshellarg', $args));

和第 110 行

return new Process($script, $this->cwd, null, $this->stdin, $this->timeout, $options);

进行更改,我希望这个错误很快得到修复,直到那时任何试图让它工作的人都会发现这个线程......带了我比如 8 小时的调试、阅读和尝试不同的方法。

Ok, I figured it out. Man, this one was brutal.

Let's start with the easy stuff. A working version of the config.yml can look like this:

assetic:
  debug: false
  use_controller: false
  java: C:\Program Files (x86)\Java\jre6\bin\java.exe
  sass: C:\Program Files (x86)\Ruby192\bin\sass.bat
  filters:
    scss: ~
    yui_js:
      jar: %kernel.root_dir%\Resources\java\yuicompressor-2.4.6.jar

For some reason, assetic is always importing a whole directory for scss, so I had to make a combine.scss which imports the other scss files in the correct order.

And now it gets ugly, as one have to change the assetics core in order to get this working. The developers of assetic know this bug and I think it is fixed in some development trunk/branch but not the stable one.

The Assetic\Util\ProcessBuilder has to be changed on line 95

if (defined('PHP_WINDOWS_VERSION_MAJOR')) {

,line 103

$script .= ' '.implode(' ', array_map('escapeshellarg', $args));

and line 110

return new Process($script, $this->cwd, null, $this->stdin, $this->timeout, $options);

I hope this bug get fixed soon and till then anybody trying to get it working finds this thread... Took me like 8 hours of debuging, reading and trying different approaches.

执笔绘流年 2024-12-24 00:03:55

Boo 11 月 19 日 22:53 的回答确实对我有用,通过更改他在 Assetic\Util\ProcessBuilder 中提到的所有内容(我忽略了第 95 行,因为它看起来与我的文件中的相同)

现在它可以在 Windows 上运行。谢谢!

只是为了确认。我使用 Symfony 2.0.7 和 yuicompressor-2.4.7

Answer by Boo Nov 19 at 22:53 did work for me by changing everything he mentioned in Assetic\Util\ProcessBuilder (I ignored line 95 as it looks the same as in my file)

Now it works on windows. Thanks!

Just to confirm. Im using Symfony 2.0.7 and yuicompressor-2.4.7

多孤肩上扛 2024-12-24 00:03:55

对于使用 Windows Server 2008 r2 的其他用户:

  1. 也许您应该将 IIS 用户/或计算机的普通用户的 C:\windows\Temp 文件夹属性更改为 777(读/写)

  2. 请从以下位置解压 ruby​​.7z rubyinstaller.org ,然后转到 C:\_ruby193\bin ,在这个解压位置你应该执行 CMD 提示符,输入:

    ruby -S gem 安装 sass
    

    这样您就可以在该位置获得 sass.bat

  3. 是时候使用Boo的最佳答案了,请注意在 symfony2 dev env 中,也许没有必要将 use_controller 更改为 false (在 config.yml 中),因为 config_dev.yml 中还有另一个 use_controller code> (设置为 true) ,并且在 routing_dev.yml 中还有一个 _assetic router ,它们可能是关联的。

For other users who use window server 2008 r2 :

  1. Maybe you should change the C:\windows\Temp folder property to 777 (read/write) for the IIS user / or the machine's normal user

  2. please unpack the ruby.7z from rubyinstaller.org , and go to C:\_ruby193\bin , in this unpack position you should exec the CMD prompt , type :

    ruby -S gem install sass
    

    so that you will get the sass.bat in that position

  3. It's time to use Boo's best answer , and please notice that in symfony2 dev env maybe it's not necessary to change the use_controller to false (in the config.yml) , because there's another use_controller in the config_dev.yml (set to true) , and in routing_dev.yml there's also a _assetic router , they're perhaps associated.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文