laravel-mix: mix.copy does not allow for the glob params.

laravel.mix.js

mix.copy('src/images/*{.png,.jpg}', 'dist/images');

Let’s say I have 2 files:

/src/images/example.png
/src/images/example.jpg

when I run the npm run webpack it copies whole images dir into dist:

/dist/images/src/images/example.png
/dist/images/src/images/example.jpg

and should be:

/dist/images/example.png
/dist/images/example.jpg

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 4
  • Comments: 16 (2 by maintainers)

Commits related to this issue

Most upvoted comments

I’m not sure about this fix - it means you can’t copy a tree without it being flattened.

My solution is to use the ‘context’ copy-webpack-plugin option. Context allows you to specify the root that the copy is relative to - rather than implying it all from the ‘from’ arg.

Something like:

mix.copy2 = function (from, to, root) {
    var options = {
        from: from,
        to: Mix.Paths.root(to)
    };
    if (root) {
        options.context = root;
    }
    Mix.copy = (Mix.copy || []).concat(options);
};

This is fixed now in #135.