对于某些人来说这可能是显而易见的,但我一直在想:我为什么要依靠Google的服务器为我的网站托管jQuery?
是不是因为它以这种方式加载得更快?
我正在使用Symfony2,Assetic和Twig.我有各种前端库 - Backbone,jQuery,jQuery UI和Bootstrap.Bootstrap和jQuery UI都包含CSS和JS文件.
有没有办法可以定义他们需要包含的资源(包括依赖项),然后在Twig/Assetic中将所有这些资源包含在一个标签中?我希望看到的是:
// config.yml <!-- DOES NOT WORK -->
assetic:
resources:
jquery:
js: /filepath/to/jquery.js
jquery_ui:
dependencies: jquery
css: /filepath/to/jqueryui.css
js: /filepath/to/jqueryui.js
less:
js: /filepath/to/less.js
bootstrap:
dependencies: { less, jquery }
js: /filepath/to/bootstrap.js
css: /filepath/to/bootstrap.css
backbone:
dependencies: { jquery }
js: { /filepath/to/underscore.js, /filepath/to/backbone.js }
// view.html.twig
{% use jquery_ui %}
{% use bootstrap %}
// outputs all js and css for jQuery, jQueryUI, Less, Backbone, and Bootstrap
Run Code Online (Sandbox Code Playgroud)
我发现了几个相关的问题:
但似乎都没有涉及在config.yml中定义资源.相反,他们定义了它们, …
我用作曲家安装了jQuery.
现在jQuery在vendor/components/jquery目录中.
我试图把它包含在内 /app/config/config.yml
assetic:
debug: "%kernel.debug%"
use_controller: false
filters:
cssrewrite: ~
assets:
jquery: %kernel.root_dir%/../vendor/components/jquery/jquery.min.js
Run Code Online (Sandbox Code Playgroud)
如果我运行命令:
php app/console assetic:dump
Run Code Online (Sandbox Code Playgroud)
我明白了
[RuntimeException]
The source file "/home/user/project/app/current/app/../web/vendor/components/jquery/jquery.min.js" does not exist.
Run Code Online (Sandbox Code Playgroud)
导致资产仍在查找/web/错误的目录.如何更改它以便在/vendor/目录中查找?此外,我不想将jquery文件放在公共包文件夹中,因为这会使通过composer获得正确版本的供应商库的所有感觉失去作用.