简体   繁体   English

为什么Symfony2捆绑包不能嵌入第三方库

[英]Why should not a Symfony2 bundle embed third-party libraries

Bundle Structure and Best Practices : 捆绑结构和最佳实践

A bundle should not embed third-party libraries written in JavaScript, CSS, or any other language. 捆绑包不应嵌入用JavaScript,CSS或任何其他语言编写的第三方库。

Why shouldn't i create for example a bootstrap , or jQuery bundle? 为什么我不应该创建一个bootstrapjQuery包?

I think it would be easier to maintain if all third-party CSS and JavaScript libraries live in their own bundle. 我认为如果所有第三方CSS和JavaScript库都存在于他们自己的包中,那么维护会更容易。

Well, for one, It's counter-intuitive. 嗯,对于一个人来说,这是违反直觉的。 Symfony Bundles are for packages of PHP functionality and you're talking about bundling up front-end libraries. Symfony Bundles用于PHP功能包,您正在谈论捆绑前端库。

Secondly - why would it be easier? 其次 - 为什么会更容易? Things like bootstrap and jQuery are public resources to begin with - they don't need a distributable bundle to achieve high re-use. 像bootstrap和jQuery这样的东西是公共资源 - 它们不需要可分发的bundle来实现高度重用。 PHP resources are not public and therefore benefit from this type of system. PHP资源公开,因此受益于此类系统。

The chaos comes when two or more bundles uses the same 3rd party library but different versions. 当两个或更多捆绑包使用相同的第三方库但版本不同时,就会出现混乱。 A user of your bundle won't be able to choose which library to include and therefore can't use both bundles at the time. 您的捆绑包的用户将无法选择要包含的库,因此当时不能同时使用这两个捆绑包。

It's fine to store them in a bundle folder if your bundle is a standalone application, ie your application's main bundle. 如果您的捆绑包是一个独立的应用程序,即您的应用程序的主捆绑包,可以将它们存储在捆绑文件夹中。 For example, SonataAdminBundle includes 3rd party libraries: bootstrap.css, qtip, famfamfam icons. 例如, SonataAdminBundle包括第三方库:bootstrap.css,qtip,famfamfam图标。

看看MopaBootstrapBundle https://github.com/phiamo/MopaBootstrapBundle它为你整合了TwitterBootstrap和jQuery lib,如果你启用了initializr插件,还有HTML5BoilerPlate。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM