var fs = require('fs');
// retorna todos os arquivos dentro do diretório dir
let getFiles = function (dir) {
return fs.readdirSync(dir).reduce((prev, file) => {
var fullPath = `${dir}/${file}`;
if (fs.statSync(fullPath).isFile()) {
// apenas terminados em .js
if (file.indexOf('.js') === file.length - 3) {
prev.push(file);
}
}
else {
// folder, recurse e retorna subpath junto com arquivo
prev = prev.concat(getFiles(fullPath).map((f) => file + '/' + f))
}
return prev;
}, []);
};
getFiles('resources/assets/js/').forEach(function(file) {
mix.js('resources/assets/js/' + file, 'public/js/' + file);
});
Upshot:
DONE Compiled successfully in 725ms
13:55:47
Asset Size Chunks Chunk Names
/js/bootstrap.js 275 kB 0 [emitted] [big] /js/bootstrap
/js/app.js 3.06 kB 1 [emitted] /js/app
/js/image-resize.min.js 29.9 kB 2 [emitted] /js/image-resize.min
/js/temp/test.js 2.95 kB 3 [emitted] /js/temp/test
/js/page-html.js 5.79 kB 4 [emitted] /js/page-html
/js/calculadora.js 5.85 kB 5 [emitted]
/js/calculadora
/css/app.css 7.92 kB 1 [emitted] /js/ap
$ ls public/js/
app.js bootstrap.js calculadora.js image-resize.min.js page-html.js temp
$ ls public/js/temp/
test.js
If your js are not in resources/assets/js adapt the calls to the desired location.
Have you ever tried something like this? mix.js('Resources/Assets/js/*. js', 'public/js');
– Diego Vieira
@Diegovieira o mix.js does not accept jokers in his sentence.
– Joao Nivaldo
Have you tried the
copyDirectory?– Valdeir Psr
@Valdeirpsr then copyDirectory it does not compile the JS, it apanas copies like this to the final directory. I need to compile to run on all browsers.
– Joao Nivaldo