// include gulp
var gulp = require('gulp');
var path = require('path');
var browserSync = require('browser-sync').create();
// include plugins
var sass = require('gulp-sass');
var cssnano = require('gulp-cssnano');
var sourcemaps = require('gulp-sourcemaps');
var rename = require('gulp-rename');
var jade = require('gulp-jade');
var jadephp = require('gulp-jade-php');
var autoprefixer = require('gulp-autoprefixer');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var plumber = require('gulp-plumber');
var assets_path = 'assets/';
var content_path = 'www/';
var template_path = 'www/';
var localhost = 'medgis.loc';
// compile sass and css files
gulp.task('sass', function(){
return gulp.src([
'assets/styles/all.scss'
])
.pipe(sourcemaps.init())
.pipe(plumber())
.pipe(sass().on('error', sass.logError))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(path.join(content_path, 'css/')));
});
gulp.task('css', ['sass'], function(){
return gulp.src(path.join(content_path, 'css/all.css'))
.pipe(plumber())
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer({
browsers: ['last 50 versions'],
cascade: false
}))
.pipe(cssnano())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest(path.join(content_path, 'css/')))
.pipe(browserSync.reload({
stream: true
}));
});
// compile pug for php files
gulp.task('views', function(){
return gulp.src([
'!assets/views/**/_*.jade',
'assets/views/index.jade'
])
.pipe(plumber())
.pipe(jade({
pretty: '\t'
}))
.pipe(gulp.dest(path.join(template_path)))
.pipe(browserSync.reload({
stream: true
}));
});
// concatenate and minify js
gulp.task('scripts', function(){
return gulp.src([
'assets/scripts/jquery.js',
'assets/scripts/main.js'
])
.pipe(plumber())
.pipe(concat('all.min.js'))
.pipe(uglify())
.pipe(gulp.dest(path.join(content_path, 'js/')))
.pipe(browserSync.reload({
stream: true
}));
});
// browser-sync task and settings
gulp.task('browserSync', ['css', 'scripts', 'views'], function(){
browserSync.init({
open: 'external',
host: localhost,
proxy: localhost,
port: 8080
});
});
// start watchers
gulp.task('watch', ['browserSync'], function(){
gulp.watch('assets/styles/**/*.scss', ['css']);
gulp.watch('assets/views/**/*.jade', ['views']);
gulp.watch('assets/scripts/**/*.js', ['scripts']);
gulp.watch('dist/**/*.html', browserSync.reload);
});