在Symfony 2中管理常见的javascript依赖项 [英] Managing common javascript dependencies in Symfony 2

查看:60
本文介绍了在Symfony 2中管理常见的javascript依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道在几个Symfony 2捆绑软件中处理常见JavaScript(甚至CSS)依赖项的标准最佳实践是什么。

I would like to know what is the standard best practice for dealing with common JavaScript (and even CSS) dependencies across several Symfony 2 bundles.

根据< a href = http://symfony.com/doc/current/book/bundles.html#vendors>在Symfony官方网站上预订:

捆绑软件不应嵌入以JavaScript,CSS或任何其他语言编写的第三方库。

此似乎是合乎逻辑的,但对于如何实际声明或要求使用诸如jQuery之类的通用资产依赖项,或更重要的是,对于jQuery的特定插件,没有建议。我强调特定的插件是因为在应用程序布局中仅包含一个众所周知的,几乎经常使用的JS框架是还可以的,但是为了以防万一,必须使用一个插件。

This seems to be logical, but there is no recommendation on how to actually declare, or require common asset dependencies such as jQuery, or more importantly, particular plugins for jQuery. I've emphasized particular plugins because just including a well known, almost always used JS framework in the application layout would be "sort of okay", but a plugin is required just in case it's going to be used.

因此,如果我不应该将其放在捆绑软件的Resources目录中,那么我的问题如下:

So if I shouldn't put it in the Resources directory of my bundle, then my questions are the following:


  • 放置第三方代码的位置

  • 我如何引用它

  • 其他捆绑软件应如何引用完全相同的插件(最好是相同的物理文件)

  • 如何不多次要求相同的资产

  • where to put the third party code
  • how do I reference it
  • how should other bundles reference the very same plugin (preferably the same physical file)
  • how not to require the same assets more than once

在不知道解决此问题的任何方法的情况下,我考虑过将说明添加到捆绑包的文档中以包括所需的内容库文件,但必须有更清洁的解决方案。

Without knowing any methods to solve this problem, I've thought of adding instructions to my bundle's documentation to include the required libs in the layout file, but there have to be cleaner solutions.

对此有何想法?

推荐答案

三分之一使用Assetic并依赖您安装依赖项的第三方插件应通过要求您在资产管理器中拥有名为(例如) jquery的资产来实现此目的。应由应用程序开发人员在config.yml中提供此资产。

A third party plugin that uses Assetic and relies on you to install a dependency should do this by requiring you to have an asset named (for instance) "jquery" in your asset manager. It's up to the application developer to provide this asset in config.yml.

这有意义吗?

这篇关于在Symfony 2中管理常见的javascript依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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