Skip to content

Instantly share code, notes, and snippets.

@yekowele
Last active May 15, 2023 21:13
Show Gist options
  • Save yekowele/5467c87e3048f873cb15487498f6d23f to your computer and use it in GitHub Desktop.
Save yekowele/5467c87e3048f873cb15487498f6d23f to your computer and use it in GitHub Desktop.
Laravel Webpack Mix - Mix all files separately in directory.
const mix = require('laravel-mix');
let fs = require('fs');
let getFiles = function (dir) {
// get all 'files' in this directory
// filter directories
return fs.readdirSync(dir).filter(file => {
return fs.statSync(`${dir}/${file}`).isFile();
});
};
getFiles('resources/js').forEach(function (JSpath) {
if(JSpath !== 'global.js' || JSpath !== 'app.js' ){ //Do not mix 'global.js' and 'app.js'
mix.js('resources/js/' + JSpath, 'public/js');
}
});
getFiles('resources/sass').forEach(function (SASSpath) {
if(SASSpath.charAt(0) !== '_'){ // Do not mix which files start with '_' (underscore)
mix.sass('resources/sass/' + SASSpath, 'public/css');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment