Skip to content

Instantly share code, notes, and snippets.

@Gyumeijie
Last active March 1, 2018 09:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gyumeijie/ff50648ce362e183c21d541b1b171648 to your computer and use it in GitHub Desktop.
Save Gyumeijie/ff50648ce362e183c21d541b1b171648 to your computer and use it in GitHub Desktop.
using babel
Assumme that we have already installed babel-cli command using `npm install --global babel-cli`.
1. Configuration .babelrc, the basic format of this file is shown as the following:
{
"presets": [],
"plugins": []
}
2. Install some plunins
For plugins allow Babel to parse specific types of syntax, So we need to install particular plunin if we need
to transform specific source code.
3. Using babel to convert src files
For example, we can use `babel "src" -d "dist"` to convert files, where the src is a directory in which source js
files are stored and the dist is the directory into which we want to ouput the transformed files.
------------------------------------------------------------------------------------------------------------------
The transpiling can be done in the following three ways:
1. Via .babelrc (Recommended)
Bable will resolve the .babelrc configuration file to do some specific transpiling work.
2. Via CLI
For example,
babel --plugins some-plugin source.js
3. Via Node API
For exapmple,
require("babel-core").transform("code", {
plugins: ["some-plugin"]
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment