How to apply different rules for a second entry in Webpack?

Viewed 77

I have two entries and am trying to adjusting the babel config based on the entry being processed.

module.exports = {
  entry: {
    'a': 'index.js',
    'b': ['polyfills.js', 'index.js'],
  },
  output: {
    filename: '[name].[chunkhash].js',
    path: './build',
  },
  rules: [
    {
      test: /\.js$/,
      exclude: /node_modules/,
      loader: "babel-loader",
      options: {
        presets: [["@babel/preset-env", {
          // If compiling for the named entry "a" do something
          // If compiling for the named entry "b" do something else
        }]],
      }
    }
  ]
}

Is this possible?

0 Answers
Related