0

In my Laravel project I have a number of javascript files and a number of coffeescript files. They're stored in the following structure:

resources/assets/js/jquery.min.js
resources/assets/js/jquery.form.js
resources/assets/coffee/main.coffee

What I would like to do using Laravel Elixir and Gulp, is to compile the coffeescript file into Javascript, and combine all 3 Javascript files into a single file and output it:

public/js/main.js

My problem seems to be that mix.scripts() only likes javascript files whereas mix.coffee() only seems to like coffeescript files, so I'm finding it difficult getting the output I need.

I'm sure I could achieve this in a "hacky" way by running mix.coffee() on my coffeescript and then running mix.scripts() on the resulting file and the other two Javascript files but I was hoping there would be a better way to achieve this.

elixir(function(mix) {

    mix.scripts([
        'jquery.min.js', 'jquery.form.js'
    ], 'public/js/main1.js');

    mix.coffee([
        'main.coffee'
    ], 'public/js/main2.js');

});
Jonathon
  • 15,873
  • 11
  • 73
  • 92
  • 1
    I've wrestled with the same issue and I think your "hacky" way is the only way. I have found that Elixir is actually quite restrictive in what it will accept and the way it handles things. It works great for the majority of use cases, but try to do anything unusual & you're in for a struggle :-) – Kryten Dec 15 '15 at 19:00
  • Thanks for your reply. Yeah that does seem to be the only way. I posted an issue/suggestion on Github and got a reply from Jeffrey Way, Elixir's author. he said that there's not really any support for doing that and to just do it the way I suggested. A combination of running `mix.coffee()` and then either using `mix.scripts()` or `mix.combine()` to build a single file after it. He said Elixir runs synchronously so it should be okay to do it that way. Not an ideal solution but it works I suppose! – Jonathon Dec 17 '15 at 12:51

0 Answers0