There's more...

If you want to implement Babel with Webpack 4 to transpile ES6 code, you need to use babel-loader, and you may need to install the following packages:

npm install --save-dev babel-loader babel-core babel-preset-env
  1. Create a .babelrc file at the root of your project and then add this code:
    {      "presets": ["env"]    }
File: .babelrc
  1. Add our babel-loader using a webpack.config.js file:
  const webpackConfig = {    module: {      rules: [        {          test: /\.js$/,          exclude: /node_modules/,          use: 'babel-loader'        }      ]    }  };  module.exports = webpackConfig;
File: webpack.config.js
  1. Create a file called src/numbers.js and import it to our src/index.js to test our babel-loader:
    export const numbers = ['one', 'two', 'three'];
File: src/numbers.js
  1. In our ...

Get React Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.