-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
65 lines (54 loc) · 1.65 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
var gulp = require('gulp');
var less = require('gulp-less');
var imagemin = require('gulp-imagemin');
var browserSync = require('browser-sync');
var sitemap = require('gulp-sitemap');
var postcss = require('gulp-postcss');
var sourcemaps = require('gulp-sourcemaps');
var autoprefixer = require('autoprefixer');
// optimise images
gulp.task('images', function(){
return gulp.src('resources/images/**/*.+(png|jpg)')
.pipe(imagemin())
.pipe(gulp.dest('resources/images'))
})
//compile less to css
gulp.task('less', function(){
return gulp.src('less/**/*.less') //grab all less files
.pipe(less()) //run the less task on them
.pipe(gulp.dest('css')) //and put the output in the css folder
.pipe(browserSync.reload({ //let gulp inject css into the browser
stream: true
}))
})
//autoprefix css
gulp.task('autoprefix', function () {
return gulp.src('css/**/*.css')
.pipe(sourcemaps.init())
.pipe(postcss([ autoprefixer() ]))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('css'));
});
//build/update the sitemap
gulp.task('sitemap', function () {
gulp.src(['./*.html', './side_projects/**/*.html'], {
read: false
})
.pipe(sitemap({
siteUrl: 'http://www.vedran.io'
}))
.pipe(gulp.dest('./'));
});
//watch files for changes
gulp.task('serve', ['less', 'autoprefix','images', 'sitemap', 'browserSync'], function(){
gulp.watch('less/**/*.less', ['less']);
gulp.watch('*.html', browserSync.reload);
})
//update the browser
gulp.task('browserSync', function() {
browserSync({
server: {
baseDir: './'
},
})
})