Laravel-mix: why not support node glob

Created on 18 Jan 2018  路  4Comments  路  Source: JeffreyWay/laravel-mix

  • Laravel Mix Version: 1.0
  • Node Version: v6.11.2
  • NPM Version: 3.10.10
  • OS: windows 7

Description:

The code below throwed an error

ENOENT: no such file or directory, open 'F:\test\laravel54\public\assets\js\*.js'

mix
    .js('resources/assets/js/**/*.js', 'public/assets/js')
    .less('resources/assets/less/**/*.less', 'public/assets/css')
    .version()

Most helpful comment

It might be a design decision to not add more scope to the library. That being said, you have access to the glob package and can achieve the above with something like this:

const glob = require('glob');

let jsFiles = glob.sync('resources/assets/js/**/*.js');
let lessFiles = glob.sync(('resources/assets/less/**/*.less');

// If combining to one entry file
mix
    .js(jsFiles, 'public/assets/js')
    .less(lessFiles, 'public/assets/css')
    .version()

// If each file is its own entry file
jsFiles.forEach(filename => {
  mix.js(filename, 'public/assets/js);
});

lessFiles.forEach(filename => {
  mix.less(filename, 'public/assets/css);
});

Also see some discussion in Webpack's own threads: https://github.com/webpack/webpack/issues/370

All 4 comments

It might be a design decision to not add more scope to the library. That being said, you have access to the glob package and can achieve the above with something like this:

const glob = require('glob');

let jsFiles = glob.sync('resources/assets/js/**/*.js');
let lessFiles = glob.sync(('resources/assets/less/**/*.less');

// If combining to one entry file
mix
    .js(jsFiles, 'public/assets/js')
    .less(lessFiles, 'public/assets/css')
    .version()

// If each file is its own entry file
jsFiles.forEach(filename => {
  mix.js(filename, 'public/assets/js);
});

lessFiles.forEach(filename => {
  mix.less(filename, 'public/assets/css);
});

Also see some discussion in Webpack's own threads: https://github.com/webpack/webpack/issues/370

I've added glob support for JS compilation, but not yet CSS.

Hey, I've writted a package to do this kind of thing :
https://www.npmjs.com/package/webpack-entry-watcher

Thanks for integrating glob support, however, the current implementation compiles everything into one file. In order to compile them separately there's still manual work required, just as https://github.com/JeffreyWay/laravel-mix/issues/1419#issuecomment-358677059 describes.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kpilard picture kpilard  路  3Comments

terion-name picture terion-name  路  3Comments

nezaboravi picture nezaboravi  路  3Comments

mementoneli picture mementoneli  路  3Comments

pixieaka picture pixieaka  路  3Comments