douhang1913 2014-04-10 19: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 01: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条)
编辑
预览

报告相同问题?

悬赏问题

  • ¥100 二维码被拦截如何处理
  • ¥15 怎么解决LogIn.vue中多出来的div
  • ¥15 优博讯dt50巴枪怎么提取镜像
  • ¥30 在CodBlock上用c++语言运行
  • ¥15 求C6748 IIC EEPROM程序固化烧写算法
  • ¥50 关于#php#的问题,请各位专家解答!
  • ¥15 python 3.8.0版本,安装官方库ibm_db遇到问题,提示找不到ibm_db模块。如何解决?
  • ¥15 TMUXHS4412如何防止静电,
  • ¥30 Metashape软件中如何将建模后的图像中的植被与庄稼点云删除
  • ¥20 机械振动学课后习题求解答
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部