Last active
February 23, 2016 11:10
-
-
Save amosuro/7b6b8e9c1c6a761b9079 to your computer and use it in GitHub Desktop.
ES6 Gulpfile Boilerplate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Expects the following modules to be installed: | |
// npm install --save babel-core babel-preset-es2015 babelify browserify gulp gulp-concat gulp-eslint gulp-rename gulp-watch gulp-minifier gulp-sass vinyl-buffer vinyl-source-stream | |
import gulp from 'gulp'; | |
import watch from 'gulp-watch'; | |
import concat from 'gulp-concat'; | |
import rename from 'gulp-rename'; | |
import sass from 'gulp-sass'; | |
import minify from 'gulp-minifier'; | |
import browserify from 'browserify'; | |
import babelify from 'babelify'; | |
import source from 'vinyl-source-stream'; | |
import buffer from 'vinyl-buffer'; | |
import eslint from 'gulp-eslint'; | |
class GulpFile { | |
constructor() { | |
gulp.task("scripts", () => this.compileJavascript()); | |
gulp.task("styles", () => this.compileCss()); | |
gulp.task("watch", ['scripts', 'styles'], () => this.watchAssets()); | |
gulp.task("default", ['scripts', 'styles', 'watch']); | |
} | |
compileJavascript() { | |
return browserify({entries: './src/main.js', debug: true}) | |
.transform("babelify", {presets: ["es2015"]}) | |
.bundle() | |
.pipe(source('scripts.min.js')) | |
.pipe(buffer()) | |
.pipe(minify({minify: true, minifyJS: true})) | |
.pipe(concat('scripts.min.js')) | |
.pipe(gulp.dest('./public/js')) | |
} | |
compileCss() { | |
return gulp.src(['./assets/css/base.scss']) | |
.pipe(sass({includePaths: [ | |
'./node_modules/normalize.css', | |
'./node_modules/flexboxgrid/css' | |
]}).on('error', sass.logError)) | |
.pipe(concat('styles.css')) | |
.pipe(minify({minify: true, minifyCSS: true})) | |
.pipe(rename('styles.min.css')) | |
.pipe(gulp.dest('./public/css')) | |
} | |
watchAssets() { | |
gulp.watch(['./assets/js/*.js', './src/**/*.js'], ['scripts']); | |
gulp.watch(['./assets/css/*.scss', './src/**/*.scss'], ['styles']); | |
return | |
}; | |
} | |
new GulpFile(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment