webpack babel react config code example

Example 1: webpack babel config

npm install -D babel-loader @babel/core @babel/preset-env webpack

Example 2: jsx babel webpack

module.exports = {
  module: {
    rules: [
      {
        test: /\.(js|jsx)$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader"
        }
      }
    ]
  }
};

Example 3: configure webpack with babel

module: {
  rules: [
    {
      test: /\.m?js$/,
      exclude: /(node_modules|bower_components)/,
      use: {
        loader: 'babel-loader',
        options: {
          presets: ['@babel/preset-env']
        }
      }
    }
  ]
}

Example 4: add webpack to react project

{  "presets": [    "@babel/preset-env",    "@babel/preset-react"  ]}

Tags:

Misc Example