【问题标题】:Symfony2 can't find jquery.js file in componentsSymfony2 在组件中找不到 jquery.js 文件
【发布时间】:2014-01-30 18:53:35
【问题描述】:

我正在尝试按照本教程在 symfony2 中安装引导程序:https://coderwall.com/p/kzyiaw

当我从终端运行此命令时:php app/consoleassetic:dump --force

我收到此错误:

17:46:25 [file+] /var/www/html/learn-symfony/app/../web/js/06837fc_part_1.js

  [RuntimeException]                                                                                      
  The source file "/var/www/html/learn-symfony/app/Resources/public/js/vendor/jquery.js" does not exist.

在 composer.json 中,我将 jquery 安装在 components 目录中:

"require": {
    ...............
    "components/jquery": "*"
}

我可以从 route/components 中找到目录和 jquery 文件,但 composer 在错误的文件夹中查找。在 config.yml 中,我在资产配置下有这个:

 assets:
    jquery_js:
        inputs:
           - '%kernel.root_dir%/Resources/public/js/vendor/jquery.js'

在app下的Resources目录中,存在的文件夹只有java和views。

为了让作曲家找到 jquery.js 文件,我应该改变什么?

【问题讨论】:

    标签: javascript php jquery symfony


    【解决方案1】:

    Composer 不需要找到文件,Assetic 需要找到它。

    我目前使用加载了组件/jquery 的 jquery,并像这样设置了资产。

    assetic:
        ... debug, filters, etc ...
        assets:
            jquery: %kernel.root_dir%/../vendor/components/jquery/jquery.min.js
            underscore: %kernel.root_dir%/../vendor/components/underscore/underscore-min.js
            and so on...
    

    这是加载文件,源为供应商目录中的 components/jquery 文件夹。

    【讨论】:

    • 作为Finlay Beaton 的回答发布的评论: 从上述解决方案中应该注意到,您不需要在 config.yml 中定义“命名资产” ,您可以在您的资产样式表或 css 中使用 %kernel.root_dir%/../vendor/components/jquery/jquery.min.js。这对 css 很重要,因为 cssrewrite 不能使用 @named_asset 表示法。
    猜你喜欢
    • 2015-04-27
    • 2013-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-07
    • 2018-06-21
    相关资源
    最近更新 更多