npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gulp-babel-external-helpers

v2.0.2

Published

Gulp plugin to add external helpers for Babel in a separate file.

Downloads

74

Readme

gulp-babel-external-helpers

For Babel 5, use [email protected]! Versions >=2 are only compatible with Babel 6.

Gulp plugin to output external helpers for Babel to a separate file.

NPM

Usage

Note: Usage with watch plugins like gulp-changed and gulp-newer is not supported, but there are workarounds.

var babel = require('gulp-babel')
var babelHelpers = require('gulp-babel-external-helpers')

gulp.task('build', function () {
  return gulp.src('src/')
    .pipe(babel({ externalHelpers: true }))
    .pipe(babelHelpers('babelHelpers.js'))
    .pipe(gulp.dest('lib/'))
})

API

babelHelpers(fileName='babelHelpers.js', outputType='global')

For documentation on the outputType parameter, see the Babel 5 docs. (This behaviour is the same in both Babel 5 and 6.)

Usage with gulp-changed, gulp-newer

Usage with plugins like gulp-changed and gulp-newer is not supported. Both gulp-babel and gulp-babel-external-helpers need to process all files in your task to be able to include all the necessary helpers. With a plugin like gulp-newer, only the changed files will be processed, and only helpers used in the changed files will be included in the generated file.

If your tasks are small, you could create a separate watch build task, and a 'normal' build task that always processes every file:

var gulp = require('gulp')
var newer = require('gulp-newer')
var babel = require('gulp-babel')
var babelHelpers = require('gulp-babel-external-helpers')

var src = 'src/**/*.js'
var dest = 'lib/'

// Use external helpers when running "gulp build"
gulp.task('build', function () {
  return gulp.src(src)
    .pipe(babel({ externalHelpers: true }))
    .pipe(babelHelpers('babelHelpers.js'))
    .pipe(dest)
})

// Use the inline helpers when watching
gulp.task('watch:build', function () {
  return gulp.src(src)
    .pipe(newer(dest))
    .pipe(babel({ externalHelpers: false }))
    .pipe(dest)
})

gulp.task('watch', function () {
  gulp.watch([src], ['watch:build'])
})

If your build tasks are more complex and you're using gulp-newer for your watch task only, you can use gulp-if to conditionally use gulp-babel-external-helpers:

var gulp = require('gulp')
var gulpif = require('gulp-if')
var newer = require('gulp-newer')
var babel = require('gulp-babel')
var babelHelpers = require('gulp-babel-external-helpers')

var watching = false

var src = 'src/**/*.js'
var dest = 'lib/'

gulp.task('build', function () {
  return gulp.src(src)
    .pipe(gulpif(watching, newer(dest)))
    .pipe(somePlugin())
    .pipe(someOtherPlugin())
    // Use the inline helpers when watching, but external helpers when doing a
    // full build.
    .pipe(babel({ externalHelpers: !watching }))
    .pipe(gulpif(!watching, babelHelpers('babelHelpers.js')))
    .pipe(gulp.dest(dest))
})

gulp.task('watch', function () {
  watching = true
  gulp.watch([src], ['build'])
})

License

MIT