Laravel Elixir: Use a wildcard without combining

I have a folder in resources/assets/sasswhich has 2 files 1.scssand2.scss

I would like to:

elixir(function (mix) {
 .sass('*.scss', './public/css/');
});

And for this to generate 1.cssand2.css

In fact, I have more than two files, and therefore I do not want to write them one by one. Any way to do this? Thanks

+4
source share
1 answer

Since you can write any JavaScript in the Gulpfile, you can use the glob module to get the file names, for example:

var elixir = require('laravel-elixir');
var glob   = require('glob');
var path   = require('path');

elixir(function (mix) {
    for (let file of glob.sync('resources/assets/sass/*.scss')) {
        mix.sass(path.basename(file), './public/css/');
    }
});

If necessary, it can be more advanced - for example, I use it with versions and user paths (and ES2015 syntax):

const elixir = require('laravel-elixir');
const glob   = require('glob');
const path   = require('path');

elixir(mix =>
{
    let build_files = [];

    for (let theme of glob.sync('resources/assets/sass/themes/*/')) {
        theme = path.basename(theme);

        mix.sass(`themes/${theme}/app.scss`, `public/css/${theme}/app.css`);
        build_files.push(`css/${theme}/app.css`);
    }

    mix.version(build_files);
});
+2
source

Source: https://habr.com/ru/post/1626624/


All Articles