-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
59 lines (51 loc) · 1.82 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
var gulp = require('gulp'),
sass = require('gulp-sass'),
autoprefixer = require('gulp-autoprefixer'),
sourcemaps = require('gulp-sourcemaps'),
minifyCss = require('gulp-clean-css'),
rename = require('gulp-rename'),
browserSync = require('browser-sync').create();
gulp.task('sass', function(){
// sass directory
return gulp.src('./sass/*scss')
.pipe(sass())
//outputstyle (nested, compact, expanded, compressed)
.pipe(sass({outputStyle:'compact'}).on('error', sass.logError))
// sourcemaps
.pipe(sourcemaps.init())
// sourcemaps output directory
.pipe(sourcemaps.write(('./maps')))
// css output directory
.pipe(gulp.dest('./css')),
// watch file
gulp.watch('./sass/*.scss', ['sass']);
});
// minify css (merge + autoprefix + rename)
gulp.task('minify-css', function(){
return gulp.src('./css/style.css')
.pipe(minifyCss())
// autoprefixer
.pipe(autoprefixer({
browsers: ['last 15 versions'],
cascade: false
}))
// minify output directory
.pipe(rename('style.min.css'))
.pipe(gulp.dest('./css'))
// browser sync
.pipe(browserSync.reload({stream: true})),
// watch file
gulp.watch('./css/style.css', ['minify-css']);
});
// sass/css browser tracking
gulp.task('browser-sync', function(){
browserSync.init({
server:{
baseDir: './'
}
});
// watch html
gulp.watch('./*.html').on('change', browserSync.reload);
});
// gulp default (sass, minify-css, browser-sync) method
gulp.task('default', ['sass', 'minify-css', 'browser-sync']);