gulpfile.js

Customised for underscore.me WordPress starter theme.

Package.json to auto download dependencies.

$ npm-check-updates -u
$ npm install --save-dev
var gulp = require('gulp');
var concat = require('gulp-concat');
var sass = require('gulp-sass');
var cleanCSS = require('gulp-clean-css');
var uglify = require('gulp-uglify');
var jshint = require('gulp-jshint');
var imagemin = require('gulp-imagemin');
var browserSync = require('browser-sync').create();

var paths = {
  scripts: './js',
  stylesheets: './layouts',
  images:'./img',
  theme: './theme',
  dist: './dist'
};

gulp.task('minify-css', function() {
  gulp.src(paths.stylesheets + '/*.css')
  .pipe(cleanCSS())
  .pipe(concat('all.min.css'))
  .pipe(gulp.dest(paths.dist));
});

gulp.task('js', function () {
  gulp.src(paths.scripts + '/*.js')
  .pipe(jshint())
  .pipe(jshint.reporter('fail'));
});

gulp.task('uglify-scripts', function() {
  return gulp.src(paths.scripts + '/*.js')
  .pipe(uglify())
  .pipe(concat('all.min.js'))
  .pipe(gulp.dest(paths.dist));
});

gulp.task('img', function() {
  gulp.src(paths.images + '/*.{png,jpg,gif}')
  .pipe(imagemin({
    optimizationLevel: 7,
    progressive: true
  }))
  .pipe(gulp.dest(paths.dist + '/img'));
});

gulp.task('sass', function () {
  return gulp.src([paths.stylesheets + '/bootstrap4alpha/*.scss',paths.stylesheets + '/*.scss'])
  .pipe(sass())
  .pipe(gulp.dest(paths.stylesheets))
  .pipe(browserSync.stream());
});

gulp.task('browser-sync', ['sass'], function() {
  browserSync.init({
    proxy: "ndp2016.localhost"
  });
  gulp.watch(paths.stylesheets + '/**/*.scss', ['sass']);
  gulp.watch(paths.theme + '/**/*.{php,js}').on('change', browserSync.reload);
});

// gulp
gulp.task('default', ['js','browser-sync']);
// gulp dist
gulp.task('dist', ['sass','minify-css','js','uglify-scripts']);
Advertisements