Babel transpilation for Grunt

8.0.0 · active · verified Sun Apr 19

grunt-babel is a Grunt plugin that integrates Babel, allowing developers to transpile modern JavaScript code (ESNext) into backward-compatible versions for older environments using the Grunt task runner. The current stable version is v8.0.0, which is specifically designed for compatibility with Babel 7.x. While Grunt itself has a slower release cadence compared to modern build tools, `grunt-babel` follows Babel's major version releases closely, necessitating updates to maintain compatibility. Its primary differentiator is its deep integration into the Grunt ecosystem, providing a familiar configuration experience for projects already utilizing Grunt for their build processes. It leverages Babel's extensive plugin and preset system, enabling a wide range of transformations, from JSX and TypeScript syntax stripping to polyfilling modern JavaScript features, making it suitable for projects that prefer a Grunt-centric workflow over newer alternatives like Webpack or Rollup.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart configures grunt-babel to transpile 'src/app.js' into 'dist/app.js' using source maps and the '@babel/preset-env' preset, then registers it as the default Grunt task.

require('load-grunt-tasks')(grunt); // npm install --save-dev load-grunt-tasks

grunt.initConfig({
  babel: {
    options: {
      sourceMap: true,
      presets: ['@babel/preset-env'] // Ensure @babel/preset-env is installed
    },
    dist: {
      files: {
        'dist/app.js': 'src/app.js'
      }
    }
  }
});

grunt.registerTask('default', ['babel']);

view raw JSON →