block by pnavarrc cb12714c95f52ce147b4cf2046e0f38a

Code examples for Writing a Babel Plugin

Writing a Babel Plugin to Refactor Code

Babel is a tool to transform code. It’s most commonly used to transform “modern” JavaScript into code that’s compatible with older browsers. Babel allows us, for example, to use arrow functions (ES2015) during development and have them transformed to anonymous functions at build-time.

// In
[1, 2, 3].map(n => n * n);

// Out
[1, 2, 3].map(function(n) { return n * n; });

example1.js