Babel 6.0.20 Modules feature not work in IE8

后端 未结 3 1858
误落风尘
误落风尘 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
    
    0 讨论(0)
  • 2020-12-02 09:44

    I also have the problem, and I wrote a webpack plugin to resolve it. I didn't really know if there is a nicer way to handle it, but it works.

    The module in node_modules also works well.

    0 讨论(0)
  • 2020-12-02 09:48

    I use webpack + es3ify-loader as workaround.

    loaders: {
      {
        test: /\.jsx?$/,
        exclude: /node_modules/,
        loaders: ['es3ify', `babel?${JSON.stringify(babelQuery)}`],
      },
    }
    
    0 讨论(0)
提交回复
热议问题