user1941537
user1941537

Reputation: 6695

Adding babel-polyfill to Webpack 4 configuration file

I want to add babel-polyfill to my webpack.config.js. Babel documentation shows how to do that:

module.exports = {
  entry: ["babel-polyfill", "./app/js"]
};

However, in my webpack.config.js I'm using more than only one entry point:

module.exports = {
    entry: {
    'js/bundle': './src/scripts/index', // generates bundle.js inside dist/js folder
    'js/another': './src/scripts/another', // generates another.js inside dist/js folder
  },
}

It generates two different bundles inside dist/js folder. But now, I don't know how to add the babel-polyfill to my entry.

I tried this:

  entry: [
    babel-polyfill,
    {
      'js/bundle': './src/scripts/index', // generates bundle.js inside dist/js folder
      'js/another': './src/scripts/another', // generates another.js inside dist/js folder
    },
  ]

but then when I try to build, I get this error: SyntaxError: Unexpected identifier

Any help?

Upvotes: 3

Views: 4043

Answers (1)

Ted Fitzpatrick
Ted Fitzpatrick

Reputation: 944

I found this thread because array forEach wasn't being transpiled when I was using the Babel loader alone, IE 11 was complaining. All I did was npm install babel-polyfill, then in my main js file I require('babel-polyfill'). Actually I didn't need to modify my webpack config. After installing babel-polyfill and requiring it, successful transpilation of forEach

Upvotes: 1

Related Questions