I setup webpack + babel config
webpack.config.js
...
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loader: 'babel-loader'
},
...
.babelrc
{
"plugins": ["lodash", "transform-object-rest-spread"],
"presets": [
["env", {
"targets": [
"> 4%",
"ie 11",
"safari 8"
]
}],
"react",
"react-optimize"
],
"env": {
"test": {
"presets": ["es2015", "react"]
}
}
}
In google chrome everything is ok, but in IE 11i have an error
Object doesn't support property or method 'assign'
You would need to add the object assign transform as well Check https://babeljs.io/docs/plugins/transform-object-assign/
Also notice that it is best practice to include a polyfill instead. The MDN usually gives a polyfill code for ES2015 features. Check https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
For the record, it is:
if (typeof Object.assign != 'function') {
Object.assign = function(target, varArgs) { // .length of function is 2
'use strict';
if (target == null) { // TypeError if undefined or null
throw new TypeError('Cannot convert undefined or null to object');
}
var to = Object(target);
for (var index = 1; index < arguments.length; index++) {
var nextSource = arguments[index];
if (nextSource != null) { // Skip over if undefined or null
for (var nextKey in nextSource) {
// Avoid bugs when hasOwnProperty is shadowed
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
to[nextKey] = nextSource[nextKey];
}
}
}
}
return to;
};
}
You want to include this code in your app for browsers that do not support Object.assign. The Babel transform plugin referred above also recommends this approach when building an app and not a library.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With