agentleFS
G1JoshiG1Joshi/Agent-Skills/skills/tools/babel/SKILL.md

babel

Skill15 starsChanged 2 months agoMITView on GitHub

Expert Babel compiler assistance covering AST transforms, presets (@babel/preset-env, @babel/preset-react), and polyfilling via core-js. Use when transpiling modern ECMAScript/TypeScript for legacy targets.

  • Installs packages

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

5 rules. About 0 are common, 1 is distinctive, and 4 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Write a Babel visitor plugin:

    line 108
  2. Very specific:

    Use useBuiltIns: "usage" with core-js to import only the exact polyfills referenced in your source code.

    line 128
  3. Very specific:

    Prefer babel.config.json over legacy .babelrc for consistent monorepo root-level configuration.

    line 129
  4. Very specific:

    Use @babel/plugin-transform-runtime to prevent duplicate helper functions across modules.

    line 131
  5. Very specific:

    Use Babel for type checking.

    line 137

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Babel

Babel is the transpiler that made ES6+ possible. While slower than SWC/esbuild, it remains the most extensible compiler with the largest plugin ecosystem.

When to Use

  • JavaScript / TypeScript Transpilation: Compiling modern ESNext, JSX, and TypeScript into backward-compatible JavaScript.
  • Custom AST Code Transformations: Developing Babel plugins to automate code instrumentation, stripping, or macro generation.
  • Polyfill Injection via core-js: Automatically injecting polyfills for target browser matrices using @babel/preset-env.
  • Legacy Framework Support: Maintaining React and Webpack toolchains that depend on Babel transpilation.

Quick Start

// babel.config.json
{
  "presets": [
    [
      "@babel/preset-env",
      {
        "targets": "> 0.25%, not dead",
        "useBuiltIns": "usage",
        "corejs": 3
      }
    ],
    ["@babel/preset-react", { "runtime": "automatic" }],
    "@babel/preset-typescript"
  ]
}

Core Concepts

Modern Project Configuration (babel.config.json)

Transpiling modern TypeScript and React for targeted browsers:

{
  "presets": [
    [
      "@babel/preset-env",
      {
        "targets": "> 0.5%, last 2 versions, not dead",
        "useBuiltIns": "usage",
        "corejs": "3.38",
        "modules": false
      }
    ],
    [
      "@babel/preset-react",
      {
        "runtime": "automatic"
      }
    ],
    "@babel/preset-typescript"
  ],
  "plugins": ["@babel/plugin-transform-runtime"]
}

Authoring a Custom Babel AST Transformation Plugin

Writing an AST visitor that removes console.log statements in production:

// plugins/babel-plugin-strip-console.js
export default function ({ types: t }) {
  return {
    name: "strip-console-plugin",
    visitor: {
      CallExpression(path) {
        const callee = path.node.callee;
        if (
          t.isMemberExpression(callee) &&
          t.isIdentifier(callee.object, { name: "console" }) &&
          t.isIdentifier(callee.property, { name: "log" })
        ) {
          path.remove();
        }
      },
    },
  };
}

Executing Babel via CLI

Transpiling directories from command line:

# Compile src/ directory to dist/ with source maps
npx babel src --out-dir dist --extensions ".ts,.tsx,.js" --source-maps inline

Common Patterns

Custom AST Plugin for Code Transformation

Problem: Stripping proprietary debug statements or injecting telemetry tokens during build time.

Solution: Write a Babel visitor plugin:

module.exports = function ({ types: t }) {
  return {
    visitor: {
      CallExpression(path) {
        if (path.get("callee").matchesPattern("console.debug")) {
          path.remove();
        }
      },
    },
  };
};

Best Practices

Do:

  • Use useBuiltIns: "usage" with core-js to import only the exact polyfills referenced in your source code.
  • Prefer babel.config.json over legacy .babelrc for consistent monorepo root-level configuration.
  • Evaluate whether modern native build tools (SWC, esbuild, Biome) can replace Babel for 10x-50x faster builds.
  • Use @babel/plugin-transform-runtime to prevent duplicate helper functions across modules.

Don't:

  • Transpile node_modules with Babel unless a third-party package ships untranspiled modern ES features.
  • Set modules: "commonjs" if your bundler (Vite, Rollup, Webpack) supports native ES modules.
  • Use Babel for type checking; use tsc --noEmit alongside Babel.

Troubleshooting

ErrorCauseSolution
SyntaxError: Support for the experimental syntax ... isn't currently enabledMissing specific Babel plugin or preset for experimental JS feature.Install and add the required @babel/plugin-proposal-* to config.
Cannot find module '@babel/core'Peer dependency @babel/core missing from project root.Run npm install --save-dev @babel/core.
Duplicate helper functions in output bundleHelpers inlined into every file instead of imported.Install @babel/plugin-transform-runtime and @babel/runtime.

References

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.