I am new to React and was learning how to set up react environment from scratch. The confusion I faced when I was trying to install babel for my project. The question is why babel package was divided into two packages: babel-cli and babel-core since both plays vital role in the proper operation of BABEL itself and I have to install both anyways. Wasn't it better to install one babel package instead of two: babel-cli and babel-core.
Asked
Active
Viewed 146 times
0
-
This should answer your question, https://stackoverflow.com/questions/32544685/babel-vs-babel-core-vs-babel-runtime – Hbarna Aug 16 '19 at 06:24
-
@Hbarna, thank you for your provided link, I have read through and it says that if we want to use babel from cli we need to install babel-cli. Ok, I have installed @babel/cli but I get an error saying I need to install @babel/core as well. So, why need to divide one package into two and tell us "Now you need to install two package". – topGun Aug 16 '19 at 06:50
-
So that you don't have to install the CLI if you don't need it? – jonrsharpe Aug 16 '19 at 06:59
1 Answers
1
If you read babel-cli
source code you can see that it require babel-core
. The babel-core is used to compile ES6 to backwards compatible version of JavaScript and more.
The babel-cli
is just some command line to help you run babel-core
.
But not all want to use babel-cli to just compile an ES6 file. Instead they may use some streaming build like gulp
or webpack
. They don't need babel-cli
to use command, they only need babel-core
to compile the code. So if you want to compile ES6 to backwards version of javascript, you must have babel-core
. There you can use either babel-cli
(for babel command) or write your own code use babel-core
to convert or use other tool like gulp
, webpack
.

DarknessZX
- 686
- 3
- 12
-
thank you very much for your great answer. I have a mere question how to use babel-core only to convert our code without babel-cli:) – topGun Aug 16 '19 at 08:04
-
@topGun https://babeljs.io/docs/en/babel-core you can read the guide here – DarknessZX Aug 16 '19 at 08:06
-
last question, webpack and gulp do not need babel-cli because they have their own cli to be used with babel-core? Gosh, so difficult to be starter :) – topGun Aug 16 '19 at 08:13
-
@topGun , yes they have their own plugin like `gulp-babel` and `babel-loader` to use. So user only include plugin in their pineline and use their own command line. – DarknessZX Aug 16 '19 at 08:16
-
@topGun I'm not quite sure about all case, maybe because of old version or something. But from `babel-loader` source code (webpack plugin), the code only use `babel-core`. So I can assume that maybe they use babel-cli for testing. – DarknessZX Aug 16 '19 at 08:34