2014-04-11 03:56
浏览 219


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": [
"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?

图片转代码服务由CSDN问答提供 功能建议

我刚刚开始使用Laravel / Composer。 我希望用编辑器自动加载器加载jquery。

我的 composer.json 文件如下所示:

“name”:“laravel / laravel”,
“description”:“Laravel Framework。”,
“license”:“ 麻省理工学院“,
”laravel / framework“:”4.1。*“,
”frameworks / jquery“:”1。*“
“app / commands”,
“app / controllers”,
“app / models”,
“app / database / migrations”,
“app / database / seeds”,
  n“app / tests / TestCase.php”
“vendor / frameworks / jquery / jquery.min.js”
“php artisan clear-compiled”,
“php artisan optimize”
“php artisan clear- 编译“,
”php artisan optimize“
“php artisan key:generate”


请注意我已将jquery添加到需求列表中并具有 将jquery.min.js添加到自动加载/文件中。 它加载,但作为纯文本,而不是作为js文件。

这一定是我正在做的蠢事,但我无法理解。 如何正确加载文件?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

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.

    解决 无用
    打赏 举报

相关推荐 更多相似问题