Skip to content

Instantly share code, notes, and snippets.

@spalger
Last active January 25, 2016 00:10
Show Gist options
  • Save spalger/5bc9d47d120c30255b70 to your computer and use it in GitHub Desktop.
Save spalger/5bc9d47d120c30255b70 to your computer and use it in GitHub Desktop.
babel transform that unlinks deleted/renamed files
import gulp from 'gulp'
import babel from 'gulp-babel'
import combiner from 'stream-combiner2'
import sourcemaps from 'gulp-sourcemaps'
import watch from 'gulp-watch'
import gulpif from 'gulp-if'
import del from 'del'
import vinylPaths from 'vinyl-paths'
gulp.task('default', function () {
const babelTransform = combiner.obj([
sourcemaps.init(),
babel({
stage: 1,
blacklist: ['regenerator'],
optional: ['runtime', 'bluebirdCoroutines']
}),
sourcemaps.write('.')
])
const unlinkEvent = ({ event }) => event === 'unlink' || event === 'unlinkDir'
return gulp.src('src/**/*')
.pipe(watch('src/**/*'))
.pipe(gulpif(/\.jsx?$/, babelTransform))
.pipe(gulp.dest('bin'))
.pipe(gulpif(unlinkEvent, vinylPaths(del)))
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment