-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
105 lines (93 loc) · 2.1 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
'use strict';
var gulp = require('gulp');
var sass = require('gulp-sass');
var watch = require('gulp-watch');
var plumber = require('gulp-plumber');
var browserSync = require('browser-sync').create();
/*
* config
*/
var CONFIG = {
watchFiles: {
html : 'src/**/*.html',
css : 'src/**/*.css' ,
sass : 'src/**/*.scss',
js : 'src/**/*.js',
jpg : 'src/**/*.jpg',
png : 'src/**/*.png',
gif : 'src/**/*.gif'
},
directory: {
dev : 'src',
release : 'dist'
}
};
/*
* copy html, js, css files
*/
gulp.task('copy', function(){
return gulp.src([
CONFIG.watchFiles.html,
CONFIG.watchFiles.js,
CONFIG.watchFiles.css], { base: CONFIG.directory.dev})
.pipe(gulp.dest(CONFIG.directory.release));
});
/*
* copy image files
*/
gulp.task('copy_images', function(){
return gulp.src([
CONFIG.watchFiles.jpg,
CONFIG.watchFiles.png,
CONFIG.watchFiles.gif], { base: CONFIG.directory.dev})
.pipe(gulp.dest(CONFIG.directory.release))
});
/*
* compile sass
*/
gulp.task('sass', function(){
return gulp.src(CONFIG.watchFiles.sass, { base: CONFIG.directory.dev})
.pipe(plumber())
.pipe(sass({outputStyle : 'expanded'})) //nested, compact, expanded, compressed
.pipe(gulp.dest(CONFIG.directory.release));
});
/*
* watch
*/
gulp.task('watch', function(){
watch([
CONFIG.watchFiles.sass], function(event){
gulp.start('sass');
});
watch([
CONFIG.watchFiles.html,
CONFIG.watchFiles.js,
CONFIG.watchFiles.css], function(event){
gulp.start('copy');
});
watch([
CONFIG.watchFiles.jpg,
CONFIG.watchFiles.png,
CONFIG.watchFiles.gif], function(event){
gulp.start('copy_images');
});
});
/*
* browser-sync
*/
gulp.task('browser-sync', function(){
browserSync.init({
server: {
baseDir: CONFIG.directory.release
}
});
//reload monitoring
watch([
CONFIG.directory.release + '/**/*'], function(event){
gulp.start('reload');
});
});
gulp.task('reload', function(){
browserSync.reload();
});
gulp.task('default', ['copy', 'copy_images', 'sass', 'watch', 'browser-sync']);