Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

gulp-babel

babel832.6kMIT8.0.0TypeScript support: definitely-typed

Use next generation JavaScript, today

gulpplugin, babel, transpiler, es2015, es2016, es2017, rewriting, transformation, syntax, codegen, desugaring, javascript, compiler

readme

This readme is for gulp-babel v8 + Babel v7 Check the 7.x branch for docs with Babel v6 usage

gulp-babel npm Build Status

Use next generation JavaScript, today, with Babel

Issues with the output should be reported on the Babel issue tracker.

Install

Install gulp-babel if you want to get the pre-release of the next version of gulp-babel.

# Babel 7
$ npm install --save-dev gulp-babel @babel/core @babel/preset-env

# Babel 6
$ npm install --save-dev gulp-babel@7 babel-core babel-preset-env

Usage

const gulp = require('gulp');
const babel = require('gulp-babel');

gulp.task('default', () =>
    gulp.src('src/app.js')
        .pipe(babel({
            presets: ['@babel/env']
        }))
        .pipe(gulp.dest('dist'))
);

API

babel([options])

options

See the Babel options, except for sourceMap and filename which is handled for you.

Source Maps

Use gulp-sourcemaps like this:

const gulp = require('gulp');
const sourcemaps = require('gulp-sourcemaps');
const babel = require('gulp-babel');
const concat = require('gulp-concat');

gulp.task('default', () =>
    gulp.src('src/**/*.js')
        .pipe(sourcemaps.init())
        .pipe(babel({
            presets: ['@babel/env']
        }))
        .pipe(concat('all.js'))
        .pipe(sourcemaps.write('.'))
        .pipe(gulp.dest('dist'))
);

Babel Metadata

Files in the stream are annotated with a babel property, which contains the metadata from babel.transform().

Example

const gulp = require('gulp');
const babel = require('gulp-babel');
const through = require('through2');

function logBabelMetadata() {
    return through.obj((file, enc, cb) => {
        console.log(file.babel.test); // 'metadata'
        cb(null, file);
    });
}

gulp.task('default', () =>
    gulp.src('src/**/*.js')
        .pipe(babel({
            // plugin that sets some metadata
            plugins: [{
                post(file) {
                    file.metadata.test = 'metadata';
                }
            }]
        }))
        .pipe(logBabelMetadata())
)

Runtime

If you're attempting to use features such as generators, you'll need to add transform-runtime as a plugin, to include the Babel runtime. Otherwise, you'll receive the error: regeneratorRuntime is not defined.

Install the runtime:

$ npm install --save-dev @babel/plugin-transform-runtime 
$ npm install --save @babel/runtime 

Use it as plugin:

const gulp = require('gulp');
const babel = require('gulp-babel');

gulp.task('default', () =>
    gulp.src('src/app.js')
        .pipe(babel({
            plugins: ['@babel/transform-runtime']
        }))
        .pipe(gulp.dest('dist'))
);

License

MIT © Sindre Sorhus

changelog

8.0.0-beta.2 (2018-03-14)

  • [Fix] Fix for sourceMapTarget removal in Babel v7.0.0-beta.41 (#149)

8.0.0-beta.1 (2018-01-26)

  • [Fix] Drop dependency on deprecated gulp-util (#137)
  • [Chore] Update repository: add CHANGELOG.md, update .gitignore, license year, update dependencies,
            add lock files, add _npm_ badge, mention `gulp-babel@next`.

8.0.0-beta.0 (2017-10-30)

  • [Breaking change] Make @babel/core a peer dependency

7.0.0 (2017-08-06)

  • [Breaking change] Make babel-core a peer dependency

7.0.0-alpha.18 (2017-08-04)

  • [Breaking change] Update to `babel-core@7.0.0-beta.18` (#112)
  • [Chore] Replace usage of ES6 by ES2015
  • [Documentation] Update README.md: update samples, fix link to issue tracker

6.1.2 (2016-01-31)

  • [Fix] Do not add .js extension to files without extension (#74)