0

currently i am doing environment setup for react.js with npm (babel, webpack and etc.) and i now i am filling webpack.config.js file and tutorial that i am following has next code :

 module: {
  rules: [
     {
        test: /\.jsx?$/,
        exclude: /node_modules/,
        loader: 'babel-loader',
        query: {
           presets: ['es2015', 'react']
        }
     }
  ]
},

and as i see in presents property there are written es2015 (ECMAScript 5) and i want to know it is better be like that or i should switch it to ES6 or ES7 because it is 2019 and even ES6 has way too more features. i just started react and if i asked something stupid, correct me. thanks

ilia
  • 339
  • 8
  • 23
  • are you using create-react-app ? – Saurabh Mistry Feb 08 '19 at 10:57
  • no i am not using, i thought it would be more professionally correct if i setup environment this way – ilia Feb 08 '19 at 10:59
  • The best way to start react.js from scatch is to use the default function `create-react-app`. Then you don't worry about webpack configurations. it's also more stable right now than few years ago. – ChrKahl Feb 08 '19 at 11:10
  • but it is my opinion to start from this point i don't like going into easy ready stuff and edit it, i consider this way, but thanks – ilia Feb 08 '19 at 11:15

2 Answers2

2

You are right, that tutorial is outdated, you should use @babel/preset-env instead. It is a single drop-in replacement for all esXXX presets.

@babel/preset-env is a smart preset that allows you to use the latest JavaScript without needing to micromanage which syntax transforms (and optionally, browser polyfills) are needed by your target environment(s). This both makes your life easier and JavaScript bundles smaller!

jayarjo
  • 16,124
  • 24
  • 94
  • 138
  • 1
    i got error just now, now i am also going to install @babel/core (i had babel-core) :D – ilia Feb 08 '19 at 11:36
2

you need @babel/preset-env package instead of es2015