Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

webpack with babel-preset-env "last 2 versions" with internet explorer

Maybe I am a little naive. The README on babel-preset-env

https://github.com/babel/babel-preset-env

says:

A Babel preset that compiles ES2015+ down to ES5 by automatically determining the Babel plugins and polyfills you need based on your targeted browser or runtime environments.

And yet, IE11 chokes on backticks and promies because webpack/babel neither transpiles down backtick templates to regular strings nor does it come up with a promise polyfill.

I am using webpack 3.4.1 and babel-core 6.2.5.

What is it that I am not getting here?

This is the use section of my webpack config for babel:

    use: [{
      loader: 'babel-loader',
      options: {
        presets: [
          [
            'env',
            {
              targets: {
                browsers: [
                  'last 2 versions'
                ]
              },
              modules: false
            }
          ]
        ],
        plugins: [
          'transform-runtime',
          'syntax-dynamic-import'
        ]
      }
    }]
like image 542
LongHike Avatar asked Sep 22 '17 13:09

LongHike


1 Answers

I was bashing my head against the wall for 2 days, because babel wasn't transpiling anything at all! Finally I found the culprit: it was that babel-loader wasn't reading .babelrc at all. After migrating to babel.config.js babel-loader now correctly uses the specified preset and polyfills.

My working babel.config.js config for @babel/core 7, @babel/present-env 7, @babel/polyfill 7, babel-loader 8:

module.exports = function (api) {
api.cache(true);

return {
    presets: [
      [
        '@babel/env', {
          useBuiltIns: 'entry',
        },
      ],
    ],
  };
};
like image 96
Moritz Avatar answered Nov 10 '22 02:11

Moritz