简体   繁体   English

Symfony2 Assetic不使用带有*符号的多个javascript文件

[英]Symfony2 Assetic not working with multiple javascript file with the * sign

I use Symfony2 and the assetic Bundle. 我使用Symfony2和资产Bundle。 (probleme when using the * sign to ask assetic to take all files) (使用*符号询问资产获取所有文件时出现问题)

Form what I have read here and there assetic allow to use multiple javascript file. 形成我在这里读到的资产允许使用多个javascript文件。

This work just fine when when I write all the file right before the <'/html> tag: 当我在<'/ html>标记之前写下所有文件时,这项工作就好了:

{% javascripts
    '@MySiteBlogBundle/Resources/public/js/test1.js' 
    '@MySiteBlogBundle/Resources/public/js/test2.js'
    '@MySiteBlogBundle/Resources/public/js/test3.js' 
%}
    <script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}    

but the same code, doesn't work if instead of listing the file, I use the * (just like this:) 但相同的代码,如果不是列出文件,我使用*(就像这样:)不起作用

{% javascripts
    '@MySiteBlogBundle/Resources/public/js/*'
  %}
    <script type="text/javascript" src="{{ asset_url }}"></script>
 {% endjavascripts %}

with the *, it works only depending on the pages which are displayed. 使用*,它仅取决于显示的页面。 I did all my javascipt test on class which are on my main twig template. 我在课堂上进行了所有javascipt测试,这些测试都在我的主要模板上。 And thoses class are displayed on all pages... So all test should be working. 并且所有页面都会显示该类...所以所有测试都应该正常工作。

Anyone ever had such probleme when using this * sign with assetic? 使用这个带有资产的*标志时,有没有人遇到过这样的问题?

Thanks for any comment/help. 感谢您的任何评论/帮助。

I noticed only two problems with assetic earlier. 我之前发现资产只有两个问题。

First, in production mode you have to dump them (php app/console assetic:dump --env=prod) before using. 首先,在生产模式中,您必须在使用之前转储它们(php app / console assetic:dump --env = prod)。 Okay, this is not a problem but you shouldn't forget it. 好吧,这不是问题,但你不应该忘记它。

Second, if you use the * sign to load all JavaScripts then the order of your scripts will be alphabetical and this can break a few dependencies among script files. 其次,如果使用*符号加载所有JavaScripts,那么脚本的顺序将按字母顺序排列,这可能会破坏脚本文件之间的一些依赖关系。 This is the reason I usually don't use the * sign. 这就是我通常不使用*符号的原因。

After few hours with the same issue, I realized you need to: 几个小时后出现同样的问题,我意识到你需要:

  1. create symbolic links (AKA symlinks ) or copy of your bundles by command: 按命令创建符号链接(AKA 符号链接 )或捆绑包的副本:

    bin/console assets:install bin / console资产:安装

    or 要么

    bin/console assets:install --symlink bin / console资产:安装--symlink

  2. in your definitions, use bundles/mysiteblog/js/* rather than @MySiteBlogBundle/Resources/public/js/* (you will see your bundle path in WEB directory after Step 1. 在您的定义中,使用bundles/mysiteblog/js/*而不是@MySiteBlogBundle/Resources/public/js/* (您将在步骤1之后在WEB目录中看到您的捆绑路径。

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

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