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
- Create a .babelrc file at the root of your project and then add this code:
{ "presets": ["env"] }
- 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;
- 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'];
- In our ...