babel/gulp-babel


Gulp plugin for Babel

https://babeljs.io

License: MIT

Language: JavaScript

Keywords: babel, gulp-plugin


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

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

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

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(logBabelMetadta())
)

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

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

Project Statistics

Sourcerank 21
Repository Size 110 KB
Stars 1,170
Forks 105
Watchers 27
Open issues 9
Dependencies 835
Contributors 22
Tags 29
Created
Last updated
Last pushed

Top Contributors See all

Sindre Sorhus Henry Zhu Charles Samborski Fabrício Matté Jesse McCarthy hemanth.hm Raine Revere Mayhem Litvinov Alexander Mario Nebl James Gary David Arvelo Jeff Lee Denis Iogansen Christopher Crouzet Maksim Anisenkov Jan Peer Stöcklmair Jakub Biesiada Benjamin Tan Blaine Bublitz

Packages Referencing this Repo

flint-gulp-babel
Turn ES6 code into vanilla ES5 with no runtime required
Latest release 5.2.2 - Updated - 1.17K stars
@exponent/gulp-babel
Turn ES6 code into vanilla ES5 with no runtime required
Latest release 7.1.0 - Updated - 1.17K stars
gulp-babel-2
Use next generation JavaScript, today
Latest release 6.1.2 - Published - 1.17K stars
gulp-babel
Use next generation JavaScript, today
Latest release 8.0.0 - Updated - 1.17K stars
gulp-6to5
Turn ES6 code into vanilla ES5 with no runtime required
Latest release 3.0.0 - Updated - 1.17K stars
gulp-babel2
Use next generation JavaScript, today
Latest release 6.1.5 - Updated - 1.17K stars
@gerhobbelt/gulp-babel
Use next generation JavaScript, today
Latest release 8.0.0-beta.20001 - Updated - 1.17K stars

Recent Tags See all

v8.0.0 August 28, 2018
v8.0.0-beta.2 March 14, 2018
v8.0.0-beta.1 January 26, 2018
v6.1.3 January 26, 2018
v7.0.1 January 26, 2018
v8.0.0-beta.0 October 30, 2017
v7.0.0 August 07, 2017
v7.0.0-alpha.18 August 04, 2017
v6.1.2 January 30, 2016
v6.1.1 November 27, 2015
v6.1.0 November 05, 2015
v6.0.0 October 30, 2015
v5.3.0 October 15, 2015
v5.2.1 August 20, 2015
v5.2.0 July 30, 2015

Something wrong with this page? Make a suggestion

Last synced: 2018-01-27 01:46:59 UTC

Login to resync this repository