-
Notifications
You must be signed in to change notification settings - Fork 4
/
Gulpfile.js
76 lines (63 loc) · 2.05 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
66
67
68
69
70
71
72
73
74
75
76
'use strict';
// Core references for this to work
var gulp = require('gulp'),
browserSync = require('browser-sync').create(),
sass = require('gulp-sass'),
sourcemaps = require('gulp-sourcemaps'),
reload = browserSync.reload,
clean = require('gulp-clean');
// var listing of files for dist build
var filesToDist = [
'./src/*.html',
'./src/css/**/*.*',
'./src/images/**/*.*',
'./src/js//**/*.js'
];
// Use for stand-alone autoprefixer
var gulpautoprefixer = require('gulp-autoprefixer');
// alternate vars if you want to use Postcss as a setup
var postcss = require('gulp-postcss'),
autoprefixer = require('autoprefixer');
// Gulp task when using gulp-autoprefixer as a standalone process
gulp.task('build:css', function() {
gulp.src('./src/sass/{,*/}*.{scss,sass}')
.pipe(sourcemaps.init())
.pipe(sass({
errLogToConsole: true,
outputStyle: 'expanded' //alt options: nested, compact, compressed
}))
.pipe(gulpautoprefixer({
browsers: ['last 4 versions'],
cascade: false
}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./src/css'))
.pipe(reload({stream: true}));
});
// Static Server + watching scss/html files
gulp.task('serve', ['build:css'], function() {
browserSync.init({
server: "./src/",
port: 8080
});
gulp.watch('./src/sass/{,*/}*.{scss,sass}', ['build:css']);
gulp.watch("./src/*.html").on('change', browserSync.reload);
});
// Sass watcher
gulp.task('sass:watch', function() {
gulp.watch('./src/sass/{,*/}*.{scss,sass}', ['build:css'])
});
// resource cleaning task
gulp.task('clean', function(){
return gulp.src(['dist/*'], {read:false})
.pipe(clean());
});
// dist build tasks
// see var filesToDist for specific files
gulp.task('build:dist',['clean'], function(){
// the base option sets the relative root for the set of files,
// preserving the folder structure
gulp.src(filesToDist, { base: './src/' })
.pipe(gulp.dest('dist'));
});
gulp.task('default', ['build:css', 'sass:watch', 'serve']);