gulp-babel-external-helpers
For Babel 5, use
gulp-babel-external-helpers@1.x
! Versions >=2 are only compatible with Babel 6.
Gulp plugin to output external helpers for Babel to a separate file.
Usage
Note: Usage with watch plugins like
gulp-changed
andgulp-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 = var newer = var babel = var babelHelpers = var src = 'src/**/*.js'var dest = 'lib/' // Use external helpers when running "gulp build"gulp // Use the inline helpers when watchinggulp gulp
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 = var gulpif = var newer = var babel = var babelHelpers = var watching = false var src = 'src/**/*.js'var dest = 'lib/' gulp gulp