gulpfile.js 1.9 KB
const gulp = require('gulp');
const nodemon = require('gulp-nodemon');
const del = require('del');
const plumber = require('gulp-plumber');
const livereload = require('gulp-livereload');
const runSequence = require('run-sequence');
const sass = require('gulp-sass');
const autoprefixr = require('gulp-autoprefixer');
const buffer = require('vinyl-buffer');
const uglify = require('gulp-uglify');
const babelify = require('babelify');
const browserify = require('browserify');
const concat = require('gulp-concat');
const tap = require('gulp-tap');

gulp.task('sass', function () {
  gulp.src('./assets/styles/*.scss')
    .pipe(plumber())
    .pipe(sass())
    .pipe(gulp.dest('./public/css'))
    .pipe(livereload());
});

gulp.task('scripts', function () {

	const scripts = [
		'./assets/scripts/*.js'
	];

	return gulp.src(scripts, { read: false }) // no need of reading file because browserify does.
	    // transform file objects using gulp-tap plugin
	    .pipe(tap(function (file) {
	      // replace file contents with browserify's bundle stream
	      file.contents = browserify({
			  entries: file.path,
			  transform: [babelify],
			  paths: [
				  './node_modules/',
				  './assets/scripts/'
			  ]
		  }).bundle();
	    }))
	    // transform streaming contents into buffer contents
	    .pipe(buffer())
	    // .pipe(uglify())
	    .pipe(gulp.dest('public/js'));
});

gulp.task('watch', function() {
  gulp.watch('./assets/styles/*.scss', ['sass']);
});

gulp.task('develop', function () {
  livereload.listen();
  nodemon({
    script: 'app.js',
    ext: 'js nunjucks',
    stdout: false
  }).on('readable', function () {
    this.stdout.on('data', function (chunk) {
      if(/^Express server listening on port/.test(chunk)){
        livereload.changed(__dirname);
      }
    });
    this.stdout.pipe(process.stdout);
    this.stderr.pipe(process.stderr);
  });
});

gulp.task('default', [
  'sass',
  'develop',
  'watch'
]);