ES2015 and Babel Features
There are some features that Babel with the babel-preset-env and/or babel-preset-es2015 presets don't cover. For example, the spread operator can be used in vuex to map getters and mutations within components like this:
import { mapMutations } from 'vuex';
export default {
methods: {
...mapMutations([
'increment',
'decrement'
])
}
}
Without the spread operator, the above mapMutations method out of vuex would have to hog the entire methods object.
Unfortunately, at the time of writing this article, the normal solution is to use the babel-preset-stage-2 preset, and that preset happens to kill a very required cross-env package needed for webpack to work on these vue projects.
The solution is to invidually install function plugins for whatever you need until this gets fixed. You'll need to do the following...
Install the plugin
npm i -D babel-plugin-transform-object-rest-spread
and include it in .babelrc along with env
{
"presets": ["env"],
"plugins": ["transform-object-rest-spread"]
}
And that's it! Enjoy the spread operator or whatever other function you need.