how to add jquery in laravel project

前端 未结 5 683
忘了有多久
忘了有多久 2020-12-09 08:11

I am new to laravel framework. I want to use jQuery in web application built using laravel framework.

But don\'t know how to link to jQuery library

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-09 08:46

    For those using npm to install packages, you can install jquery via npm install jquery and then use elixir to compile jquery and your other npm packages into one file (e.g. vendor.js). Here's a sample gulpfile.js

    var elixir = require('laravel-elixir');
    
    elixir(function(mix) {
        mix
    
        .scripts([
            'jquery/dist/jquery.min.js',
            // list your other npm packages here
        ],
        'public/js/vendor.js', // 2nd param is the output file
        'node_modules')        // 3rd param is saying "look in /node_modules/ for these scripts"
    
        .scripts([
            'scripts.js'       // your custom js file located in default location: /resources/assets/js/
        ], 'public/js/app.js') // looks in default location since there's no 3rd param
    
        .version([             // optionally append versioning string to filename
            'js/vendor.js',    // compiled files will be in /public/build/js/
            'js/app.js'
        ]);
    
    });
    

提交回复
热议问题