How to use Babel without Webpack

How to use Babel without Webpack

You can simply run babel through the command line:

babel --plugins transform-react-jsx-source script.js

Docs: https://babeljs.io/docs/plugins/transform-react-jsx-source/

Note the three "Usages" on the page. All of them will get you what you want, none of them use webpack. The .babelrcfile can handle all your plugins/transforms and is the recommended usage. Then you just run babel

Here is an example from Material-UI's package.json

"build:es2015": "cross-env NODE_ENV=production babel ./src --ignore *.spec.js --out-dir ./build",

Plugins

Babel is a compiler (source code => output code). Like many other compilers it runs in 3 stages: parsing, transforming, and printing.

Now, out of the box Babel doesn't do anything. It basically acts like const babel = code => code; by parsing the code and then generating the same code back out again. You will need to add plugins for Babel to do anything.

Instead of individual plugins, you can also enable a set of plugins in a preset.

 

Transform Plugins

These plugins apply transformations to your code.

Transform plugins will enable the corresponding syntax plugin so you don't have to specify both.   

原文地址:https://www.cnblogs.com/chucklu/p/14308168.html