Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
gulp-babel
Advanced tools
The gulp-babel package is a Gulp plugin that allows you to use Babel to transpile your JavaScript files. Babel is a JavaScript compiler that lets you use next-generation JavaScript, today. It can transform syntax, polyfill features that are missing in your target environment, and more.
Transpile ES6 to ES5
This feature allows you to transpile ES6 JavaScript code to ES5, making it compatible with older browsers. The code sample demonstrates a Gulp task that reads a JavaScript file from the 'src' directory, uses Babel to transpile it, and then writes the output to the 'dist' directory.
const gulp = require('gulp');
const babel = require('gulp-babel');
gulp.task('default', () => {
return gulp.src('src/app.js')
.pipe(babel({
presets: ['@babel/env']
}))
.pipe(gulp.dest('dist'));
});
Use Babel plugins
This feature allows you to use specific Babel plugins to transform your code. The code sample demonstrates a Gulp task that uses the Babel plugin for transforming arrow functions.
const gulp = require('gulp');
const babel = require('gulp-babel');
gulp.task('default', () => {
return gulp.src('src/app.js')
.pipe(babel({
plugins: ['@babel/plugin-transform-arrow-functions']
}))
.pipe(gulp.dest('dist'));
});
Source Maps
This feature allows you to generate source maps for your transpiled code, which can be very useful for debugging. The code sample demonstrates a Gulp task that initializes source maps, transpiles the code using Babel, and then writes the source maps to the 'dist' directory.
const gulp = require('gulp');
const babel = require('gulp-babel');
const sourcemaps = require('gulp-sourcemaps');
gulp.task('default', () => {
return gulp.src('src/app.js')
.pipe(sourcemaps.init())
.pipe(babel({
presets: ['@babel/env']
}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('dist'));
});
The gulp-typescript package is a Gulp plugin for compiling TypeScript files. It offers similar functionality to gulp-babel but is specifically designed for TypeScript. It can compile TypeScript to JavaScript, generate declaration files, and more.
The gulp-coffee package is a Gulp plugin for compiling CoffeeScript files. Like gulp-babel, it allows you to transpile code from one language to another, but it is specifically for CoffeeScript.
The gulp-uglify package is a Gulp plugin for minifying JavaScript files. While it doesn't transpile code like gulp-babel, it is often used in conjunction with gulp-babel to minify the transpiled code for production.
This readme is for gulp-babel v8 + Babel v7 Check the 7.x branch for docs with Babel v6 usage
Use next generation JavaScript, today, with Babel
Issues with the output should be reported on the Babel issue tracker.
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
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'))
);
See the Babel options, except for sourceMap
and filename
which is handled for you.
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'))
);
Files in the stream are annotated with a babel
property, which contains the metadata from babel.transform()
.
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())
)
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'))
);
MIT © Sindre Sorhus
8.0.0-beta.1 (2018-01-26)
gulp-util
(#137)CHANGELOG.md
, update .gitignore
, license year, update dependencies,
add lock files, add npm badge, mention gulp-babel@next
.FAQs
Use next generation JavaScript, today
The npm package gulp-babel receives a total of 315,071 weekly downloads. As such, gulp-babel popularity was classified as popular.
We found that gulp-babel demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?
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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.