March 24, 2021, update
This is tip is no longer needed for recent versions of laravel-mix
Original post
Laravel-mix is the very nice wrapper package around webpack 2 written by Jeffrey Way, the guy from Laracasts. With Laravel-mix it is easy to get your frontend running with webpack. However, the spread operator, which you can use to easily clone-and-change objects (and do many other things with) is not included in Laravel-mix. There is a good reason not to include it because
“It’s an experimental Babel feature, and not part of the main ES2015 preset.”
So this will be included in Laravel-mix as soon as it becomes available in ES2016 I guess. For the moment however, we can use the following workaround where we apply the babel plugin which enables the spread operator:
- npm install –save-dev babel-plugin-transform-object-rest-spread
- Add the following to your .babelrc file (saved in the root of your project):
{ "plugins": ["transform-object-rest-spread"] }
That’s it for this quick tip!