Laravel-mix and the spread operator

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:

  1. npm install –save-dev babel-plugin-transform-object-rest-spread
  2. 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!


Mijn Twitter profiel Mijn Facebook profiel
Pim Hooghiemstra Webdeveloper and founder of PLint-sites. Loves to build complex webapplications using Vue and Laravel! Latest post
Deploying a vue-cli app to a subfolder

Leave a Reply

Your email address will not be published. Required fields are marked *