using babel with webpack code example

Example 1: jsx babel webpack

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

Example 2: configure webpack with babel

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

Example 3: configure webpack, babel to work with node

npm install [email protected] [email protected] [email protected] @babel/[email protected] [email protected] @babel/[email protected] @babel/[email protected] --save-dev

Tags:

Misc Example