babel-core
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
babel-code-frame | 6.26.0 | 2.86 kB | MIT | prod | |
babel-generator | 6.26.1 | 18.21 kB | MIT | prod | 2 |
babel-helpers | 6.24.1 | 4.8 kB | MIT | prod | 1 2 |
babel-messages | 6.23.0 | 2.28 kB | MIT | prod | 2 |
babel-register | 6.26.0 | 4.24 kB | MIT | prod | 2 |
babel-runtime | 6.26.0 | 13.06 kB | MIT | prod | 2 |
babel-template | 6.26.0 | 2.44 kB | MIT | prod | 1 2 |
babel-traverse | 6.26.0 | 29.54 kB | MIT | prod | 1 2 |
babel-types | 6.26.0 | 20.83 kB | MIT | prod | 2 |
babylon | 6.18.0 | 67.62 kB | MIT | prod | |
convert-source-map | 1.9.0 | 3.91 kB | MIT | prod | |
debug | 2.6.9 | 16.13 kB | MIT | prod | |
json5 | 0.5.1 | 13.21 kB | MIT | prod | 1 |
lodash | 4.17.21 | 311.49 kB | MIT | prod | |
minimatch | 3.1.2 | 11.66 kB | ISC | prod | |
path-is-absolute | 1.0.1 | 1.84 kB | MIT | prod | |
private | 0.1.8 | 5.12 kB | MIT | prod | |
slash | 1.0.0 | 1020 B | MIT | prod | |
source-map | 0.5.7 | 185.31 kB | BSD-3-Clause | prod |
"Babel-core" serves as the compiler core for Babel, a widely-renowned JavaScript compiler used by developers globally. It provides an essential function by transforming your ES6+/JSX/TypeScript code into a version of JavaScript that can be understood and processed across various browsers or platforms. This ensures backward compatibility of your code irrespective of the environment it runs on, thus extending its reach and performance excellence.
To use "babel-core", you need to define it in your JavaScript file and utilize its fantastic transformation methods. Here are some examples:
To transform a code string, you can use the babel.transform()
method.
var babel = require("babel-core");
var result = babel.transform("code();", options);
console.log(result.code);
console.log(result.map);
console.log(result.ast);
The babel.transformFile()
method asynchronusly transforms the entire contents of a file.
var babel = require("babel-core");
babel.transformFile("filename.js", options, function (err, result) {
if (err) console.error(err);
console.log(result.code);
console.log(result.map);
console.log(result.ast);
});
For synchronous transformation, babel.transformFileSync()
can be used.
var babel = require("babel-core");
var result = babel.transformFileSync("filename.js", options);
console.log(result.code);
When you have an existing AST, you can still transform it using babel.transformFromAst()
.
var babel = require("babel-core");
const code = "if (true) return;";
const ast = babylon.parse(code, { allowReturnOutsideFunction: true });
const result = babel.transformFromAst(ast, code, options);
console.log(result.code);
console.log(result.map);
The robust documentation for "babel-core" can be accessed through the package's GitHub repository (Babel GitHub). The README.md file mentioned contains a comprehensive guide on using the package, including specific methods for transforming code, files, and syntax trees, and a rich list of configurable options. Links to external resources for further reading and understanding are also provided. The docs are easy to understand and replete with code samples to kickstart your development process with Babel.