Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple gulpfile for building css, js, html and assets with compass, browserify, nunjucks and moving them from app to _build folder
var gulp = require('gulp');
autoprefixer = require('gulp-autoprefixer'),
browserify = require('browserify'),
clean = require('gulp-clean'),
compass = require('gulp-compass'),
es = require('event-stream'),
glob = require('glob'),
rename = require('gulp-rename'),
source = require('vinyl-source-stream'),
nunjucks = require('gulp-nunjucks');
gulp.task( 'compass', function() {
gulp.src( './app/**/*.scss' )
.pipe( compass({
config_file: './config.rb',
css: './_build',
sass: './app/'
}) )
.pipe( autoprefixer() )
.pipe( gulp.dest( './build' ) );
});
gulp.task( 'browserify', function( done ) {
glob('./app/**/*.js', function( err, files ) {
if ( err ) {
done( err );
}
var tasks = files.map( function( file ) {
return browserify( { entries: [ file ] } )
.transform( 'babelify', { presets: [ 'es2015' ] } )
.bundle()
.pipe( source( file ) )
.pipe( rename( function ( path ) {
path.dirname = path.dirname.replace( /app\/?/, '' );
} ) )
.pipe( gulp.dest( './_build' ) );
});
es.merge( tasks ).on( 'end', done );
});
});
gulp.task( 'nunjucks', function() {
gulp.src( './app/**/*.html' )
.pipe( nunjucks.compile() )
.pipe( gulp.dest( './_build' ) );
});
gulp.task( 'assets-copy', function() {
gulp.src([
'./app/**/*',
'!./app/**/*.js',
'!./app/**/*.scss',
'!./app/**/*.html'
])
.pipe( gulp.dest( '_build' ) );
});
gulp.task('clean', function() {
return gulp.src( '_build', { read: false } )
.pipe( clean() );
});
gulp.task( 'w', [ 'default' ], function() {
gulp.watch( './app/**/*.html', [ 'nunjucks' ] );
gulp.watch( './app/**/*.js', [ 'browserify' ]);
gulp.watch( './app/**/*.scss', [ 'compass' ]);
gulp.watch([
'./app/**/*',
'!./app/**/*.js',
'!./app/**/*.scss',
'!./app/**/*.html'
], [ 'assets-copy' ]);
});
gulp.task( 'default', [ 'clean' ], function() {
gulp.start( 'compass', 'browserify', 'nunjucks', 'assets-copy' );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.