Search code examples
laravelbowerlaravel-5laravel-elixir

Laravel Elixir and Bower: Mixing javascript issue


I have my Bower vendor directory at resources/assets/vendor.

In my gulpfile, I've tried the following:

mix.scripts([
    "vendor/jquery/dist/jquery.min.js"
], "public/js");

When I run gulp in terminal, it doesn't seem to do anything. No errors though.

I also tried this:

mix.copy('vendor/jquery/dist/jquery.min.js', 'public/js/jquery.js');

To no avail.

What am I missing?

update & solution

Only sass,less and coffee scripts are by default looked for in resources/assets/[sass/coffee/less] while JS files are simply in resources/js which confused me. Beware.


Solution

  • First of all, we don't know location of your jquery.min.js file. However the default location for scripts files is resources/js so to make it work, you should have your jquery.min.js file in resources/js/vendor/jquery/dist/jquery.min.js.

    As 2nd argument you should pass your target filename with path, so it should be for example:

    mix.scripts([
        "vendor/jquery/dist/jquery.min.js"
    ], "public/js/jquery.min.js");
    

    assuming as I mentioned at the beginning you have this JS file in resources/js/vendor/jquery/dist/jquery.min.js location

    If you don't, you should use 3rd parameter. So in this case, if your JS file is really in "vendor/jquery/dist/jquery.min.js" location, you could use:

    mix.scripts([
        "jquery.min.js"
    ], "public/js/jquery.min.js", "vendor/jquery/dist");
    

    to make it work.

    EDIT

    After explaining in comments, you should use then:

    mix.scripts([
        "vendor/jquery/dist/jquery.min.js"
    ], "public/js/jquery.min.js", "resources/assets/js");