Be the first user to complete this post

  • 0
Add to List

webpack with babel6 and react

In this post we will walk through the basic setup to make babel6 work with webpack. Assuming you have installed webpack. On a high level, Babel has the following architecture. Click on the image to see the enlarged version of it. webpack-architecture

Install core modules & Add the webpack config to parse the .js | .jsx files with babel loader

npm i --save-dev babel-loader
npm i --save-dev babel-core
// webpack.config.js

module: {
  loaders: [
    { test: /.js|.jsx$/, exclude: /node_modules/, loader: "babel-loader" }
Note: "babel-loader" or "babel" both refers to the same loader.

Add babel config to tell babel how to transform the parsed files

Presets are the array of plugins. Most frequently used presets with the react project are the following.
npm i --save-dev babel-preset-stage-2
npm i --save-dev babel-preset-react
npm i --save-dev babel-preset-es2015

  "presets": [

Also Read:

  1. Pass props to the handler component in react-router
  2. Passing the store down implicitly via context in a react redux app
  3. Sublime Text plugins to boost your productivity
  4. Disable eslint no-unused-vars warning on global functions
  5. Generating container components with connect utility in react redux app
  6. combineReducers in reduxjs explained
  7. Pass down props using React childContextTypes in a deeply nested component tree
  8. Dynamic module loading with require