Skip to content

Instantly share code, notes, and snippets.

@samthor
Created July 21, 2016 02:15
Show Gist options
  • Save samthor/8d72fd31063bdce855af0261cb9ee9c2 to your computer and use it in GitHub Desktop.
Save samthor/8d72fd31063bdce855af0261cb9ee9c2 to your computer and use it in GitHub Desktop.
Gulpfile that compiles with Babel
/*
* Copyright 2016 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
const gulp = require('gulp');
const browserify = require('browserify');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
const babel = require('gulp-babel');
gulp.task('scripts', function() {
return browserify({
entries: 'index.js',
}).bundle()
.pipe(source('index-compiled.js'))
.pipe(buffer()) // turns this into a "real file", and not a stream
.pipe(babel({
presets: ['es2015'], // es2015 specifies const, let, etc
}))
.pipe(gulp.dest('./'));
});
gulp.task('default', ['scripts']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment