Babel 6.0.20 Modules feature not work in IE8

后端 未结 3 1866
误落风尘
误落风尘 2020-12-02 09:17

I am trying to export a es6 module in header.js:

export default {
    setHeaderHighlight: function (index) {
        // do somethings
    }
};
<         


        
3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-02 09:38

    By default, Babel 6.x requires you to enable an explicit set of transformations. The standard es2015 preset converts ES6 to ES5, however IE8 is not ES5-compatible. In this case, if you look at the plugins list, you will see

    • transform-es3-member-expression-literals
    • transform-es3-property-literals

    These will convert your properties to be compatible with IE8. Generally in Babel 6.x you'd do this by passing those names as part of your plugins array, alongside the presets array and install the transforms via

    npm install --save-dev babel-plugin-transform-es3-member-expression-literals babel-plugin-transform-es3-property-literals
    

提交回复
热议问题