-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
107 lines (90 loc) · 2.77 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
106
107
var gulp = require('gulp'),
gutil = require('gulp-util'),
coffee = require('gulp-coffee'),
browserify = require('gulp-browserify'),
compass = require('gulp-compass'),
connect = require('gulp-connect'),
gulpif = require('gulp-if'),
uglify = require('gulp-uglify'),
minifyHTML = require('gulp-minify-html'),
jsonminify = require('gulp-jsonminify'),
imagemin = require('gulp-imagemin'),
pngcrush = require('imagemin-pngcrush'),
concat = require('gulp-concat');
var env, coffeeSources, jsSources, sassSources, htmlSources, jsonSources, outputDir, sassStyle;
env = process.env.NODE_ENV || 'production';
if(env==='development')
{
outputDir = 'builds/development/';
sassStyle = 'expanded';
}else{
outputDir = 'builds/production/';
sassStyle = 'compressed';
}
coffeeSources = ['components/coffee/*.coffee'];
jsSources = ['components/scripts/*.js'];
sassSources = ['components/sass/style.scss'];
htmlSources = [outputDir+'*.html'];
jsonSources = [outputDir+'js/*.json'];
gulp.task('coffee', function(){
gulp.src(coffeeSources)
.pipe(coffee({bare: true})
.on('error', gutil.log)
).pipe(gulp.dest('components/scripts'))
});
gulp.task('js', function(){
gulp.src(jsSources)
.pipe(concat('script.js'))
.pipe(browserify())
.pipe(gulpif(env==='production', uglify()))
.pipe(gulp.dest(outputDir+'/js'))
.pipe(connect.reload())
});
gulp.task('compass', function(){
gulp.src(sassSources)
.pipe(compass({
sass: 'components/sass',
images: outputDir+'images',
style: sassStyle
}))
.on('error', gutil.log)
.pipe(gulp.dest(outputDir+'css'))
.pipe(connect.reload())
});
gulp.task('html', function(){
gulp.src('builds/development/*.html')
.pipe(gulpif(env==='production', minifyHTML()))
.pipe(gulpif(env==='production', gulp.dest(outputDir)))
.pipe(connect.reload());
});
gulp.task('json', function(){
gulp.src('builds/development/js/*.json')
.pipe(gulpif(env==='production', jsonminify()))
.pipe(gulpif(env==='production', gulp.dest(outputDir)))
.pipe(connect.reload());
});
gulp.task('image', function(){
gulp.src('builds/development/**/*.*')
.pipe(gulpif(env==='production', imagemin({
progressive: true,
svgoPlugins:[{removeViewBox:false}],
use:[pngcrush()]
})))
.pipe(gulpif(env==='production', gulp.dest(outputDir+'images')))
.pipe(connect.reload());
});
gulp.task('connect', function(){
connect.server({
root: outputDir,
livereload: true
});
});
gulp.task('watch', function(){
gulp.watch(coffeeSources,['coffee']);
gulp.watch(jsSources,['js']);
gulp.watch('components/sass/*.scss',['compass']);
gulp.watch('builds/development/*.html',['html']);
gulp.watch('builds/development/*.json',['json']);
gulp.watch('builds/development/**/*.*',['images']);
});
gulp.task('default',['html','json','coffee','js','compass','image','watch','connect']);