Managing common javascript dependencies in Symfony 2

痴心易碎 提交于 2019-12-20 11:45:13

问题


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.

According to the Book on the official Symfony site:

A bundle should not embed third-party libraries written in JavaScript, CSS, or any other language.

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.

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.

Any thoughts on this?


回答1:


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.

Does that make sense?



来源:https://stackoverflow.com/questions/6221536/managing-common-javascript-dependencies-in-symfony-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!