Socket
Book a DemoInstallSign in
Socket

gulp-babel2

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-babel2

Use next generation JavaScript, today

latest
Source
npmnpm
Version
6.1.5
Version published
Maintainers
1
Created
Source

gulp-babel 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-preset-es2015

Usage

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

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

API

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

/**
 * @see https://github.com/isaacs/node-lru-cache#options
 */
type lruOptions = {
	max: ?number,
	length: ?Function,
	dispose: ?Function,
	maxAge: ?number
};

/**
 * @see See the Babel options (https://babeljs.io/docs/usage/options/), except for `sourceMap` and `filename` which is handled for you.
 */
type babelOptions = {};

const babel = createBabel({max: 500}: lruOptions);

babel({}: babelOptions);

Source Maps

Use gulp-sourcemaps like this:

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

const babel = createBabel();

gulp.task('default', () =>
	gulp.src('src/**/*.js')
		.pipe(sourcemaps.init())
		.pipe(babel({
			presets: ['es2015']
		}))
		.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 createBabel = require('gulp-babel');
const through = require('through2');

const babel = createBabel();

function logFileHelpers() {
	return through.obj((file, enc, cb) => {
		console.log(file.babel.usedHelpers);
		cb(null, file);
	});
}

gulp.task('default', () =>
	gulp.src('src/**/*.js')
		.pipe(babel({
			presets: ['es2015']
		}))
		.pipe(logFileHelpers())
)

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 createBabel = require('gulp-babel');

const babel = createBabel();

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

License

MIT © Sindre Sorhus

Keywords

gulpplugin

FAQs

Package last updated on 07 Mar 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts