Search code examples
gulplaravel-5laravel-elixir

Laravel Elixir: Watch all files in a given directory?


In Grunt, I could specify a regular expression like the following to compile all files in the given directory.

"<%= path.build.less %>/custom/modules/**/*.less"

I keep going over the videos and docs on laravel and laracasts but I don't see this option, yet feel that it has to be possible.

Does anyone know if this is possible to acheive with Gulp/Elixir?

I don't want to have to keep adding less files to the array like the example below:

elixir(function(mix) {
    mix.less([
        "plugins/bootstrap.less",
        "custom/custom.less",
        "custom/module1.less",
        "custom/module2.less",
        "custom/module3.less",
        "custom/module4.less",
        "custom/module5.less",
        "custom/module6.less",
        "custom/module7.less",
    ], 'public/assets/css');
});

Solution

  • You don't have to explicitly add every file. This:

    elixir(function(mix) {
        mix.less([
            "plugins/bootstrap.less",
            "custom/module*.less"
        ], 'public/assets/css');
    });
    

    or this:

    elixir(function(mix) {
        mix.less([
            "plugins/bootstrap.less",
            "custom/modules/**/*.less"
        ], 'public/assets/css');
    });
    

    should work just as well.

    If you decide to compile multiple files to a single stylesheet, this approach won't work though since it doesn't ensure that the files will be compiled in the correct order.

    In your example it doesn't matter but it is something that should probably be kept in mind.