Symfony 2 - 使用资产 [英] Symfony 2 - Working with assets

查看:19
本文介绍了Symfony 2 - 使用资产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些关于如何在 Symfony 2 中使用资产的技巧.例如,我们是否必须在每次添加图像时始终执行资产:更新?我知道 Assetic 负责 css 和 javascript 文件的管理,但是图像呢?Symfony 2 前端开发的最佳实践是什么?你们如何在应用中设置 css、图像和 js 文件以使其易于开发、部署和更改?

I need some tips on how to work with assets in Symfony 2. For example, do we have to always perform the assets:update every time an image is added ? I know Assetic take care of the management on css and javascript files but what about images? What would be the best practice for the front-end development with Symfony 2 ? How do you guys setup your css, images and js files in your app to make it easy to develop, deploy and change ?

推荐答案

关于图片,如果你把它添加到你的公共文件夹中,我认为没有必要执行assets:update

Regarding images, if you added it into your public folder, I think there's no need to perform assets:update

但是,如果您将图像添加到捆绑包的资源文件夹中,则可能必须这样做,具体取决于您的操作系统以及调用 assets:install

However, if you add the image within the resources folders of a bundle, you might have to, depending on your OS and which options you used when called assets:install

如果您使用的是支持符号链接的操作系统(Linux、OS X,我猜除了 Windows 之外的所有操作系统),您可以安装资产调用(我不完全记得调用,这里重要的是符号链接选项):

If you're using an OS which supports symlinks (linux, OS X, and I guess all OS but Windows), you can install the assets calling (I don't exactly remember the call, the important thing here is the symlink option):

php app/console assets:install web --symlink

这样,您将拥有一个符号链接,而不是拥有每个包资源的副本,因此无需更新.如果您的操作系统不支持符号链接,我认为您必须不断更新或重新安装资产(实际上,我一直使用 assets:install,我不知道有更新选项:P).

This way, instead of having a copy of each bundle's resources, you'll have a symlink, so there should be no need to update. If you have an OS which doesn't support symlinks, I think you'll have to keep updating or reinstalling assets (in fact, I always used assets:install, I didn't knew there was an update option :P).

关于设置,如果只在bundle内使用,我通常把所有css、js、images和任何公共资源放在一个bundle中,如果它被很多bundle使用,则把它放到public文件夹中,或者我计划在其他包中使用它.

Regarding the set up, I usually put all css, js, images and any public resources inside a bundle if it is used only within the bundle, and place it onto the public folder if it's used by many bundles, or I plan to use it in other bundles.

这篇关于Symfony 2 - 使用资产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆