Skip to content

Instantly share code, notes, and snippets.

@dallasread
Last active October 19, 2015 22:41
Show Gist options
  • Save dallasread/1ff74d4f56a1fa206743 to your computer and use it in GitHub Desktop.
Save dallasread/1ff74d4f56a1fa206743 to your computer and use it in GitHub Desktop.
Basic Gulpfile.js
var browserify = require('browserify'),
source = require('vinyl-source-stream'),
buffer = require('vinyl-buffer'),
uglify = require('gulp-uglify'),
gulp = require('gulp'),
sass = require('gulp-sass'),
minifyCSS = require('gulp-minify-css'),
gulpif = require('gulp-if'),
rename = require('gulp-rename'),
stringify = require('stringify'),
argv = require('yargs').argv,
header = require('gulp-header'),
production = !!argv.production;
console.log('ENV:', production ? 'Production' : 'Development');
gulp.task('js', function() {
var bundler = browserify({
entries: ['./js/index.js']
})
.transform(
stringify({
extensions: ['.html', '.md', '.hbs'],
minify: false,
minifier: {
extensions: ['.html'],
options: {
removeComments: true,
collapseWhitespace: true
}
}
})
);
var bundle = function() {
return bundler
.bundle()
.pipe(source('./js/index.js'))
.pipe(buffer())
.pipe(rename('script.js'))
.pipe(gulpif(production, uglify()))
.pipe(gulp.dest('./'));
};
return bundle();
});
gulp.task('scss', function () {
gulp.src('./scss/index.scss')
.pipe(sass())
.pipe(minifyCSS())
.pipe(header('/* Gov.vote 2015 */'))
.pipe(rename('./style.css'))
.pipe(gulp.dest('./'));
});
gulp.task('watch', ['default'], function(){
gulp.watch(['scss/**/*'], ['scss']);
gulp.watch(['js/app/**/*'], ['js']);
});
gulp.task('default', ['scss', 'js']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment