douhang1913 2014-04-11 03:56
浏览 225
已采纳

如何使用Composer将jQuery包自动加载到Laravel

I'm just getting started with Laravel / Composer. I want jquery to load with the composer autoloader.

My composer.json file looks like this:

{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
    "laravel/framework": "4.1.*",
    "frameworks/jquery": "1.*"
},
"autoload": {
    "classmap": [
        "app/commands",
        "app/controllers",
        "app/models",
        "app/database/migrations",
        "app/database/seeds",
        "app/tests/TestCase.php"
    ],
    "files":[
        "vendor/frameworks/jquery/jquery.min.js"
    ]
},
"scripts": {
    "post-install-cmd": [
        "php artisan clear-compiled",
        "php artisan optimize"
    ],
    "post-update-cmd": [
        "php artisan clear-compiled",
        "php artisan optimize"
    ],
    "post-create-project-cmd": [
        "php artisan key:generate"
    ]
},
"config": {
    "preferred-install": "dist"
},
"minimum-stability": "stable"

}

notice i've added jquery to the require list and have added the jquery.min.js to the autoload / files. It loads, but as plain text, not as a js file.

This has to be something stupid I'm doing, but I can't figure it out. How do I get the file to load properly?

  • 写回答

2条回答 默认 最新

  • dongzhi4239 2014-04-11 09:56
    关注

    You cannot autoload jQuery with composer, because that would mean you want to execute Javascript on the server with the PHP script engine. This will never work.

    What you want to do is include jQuery in the page you are creating with PHP. Probably include it as a javascript tag that loads it. Which means you have to configure a way to make that jquery.min.js file available on the server for HTTP access.

    The frameworks/jquery package does not have any suggestions on how to do this. It simply grabs the files and adds it to the vendor folder. If you want it made available to the browser you'd either copy it into the document root, setup a script that reads the file and sends it to the browser, set a symlink to it, or add an alias to that vendor directory. All of these solutions are not that nice, but if asked I'd prefer the copy step.

    There is a components/jquery package that uses another package to allow easy configuration of where to drop the files. You should investigate that, read the README. It looks much nicer to maintain and will essentially do the copy step.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决