-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
115 lines (101 loc) · 3.11 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
108
109
110
111
112
113
114
115
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 || 'development';
if (env==='development') {
outputDir = 'builds/development/';
sassStyle = 'expanded';
} else {
outputDir = 'builds/production/';
sassStyle = 'compressed';
}
coffeeSources = ['components/coffee/tagline.coffee'];
jsSources = [
'components/scripts/rclick.js',
'components/scripts/pixgrid.js',
'components/scripts/tagline.js',
'components/scripts/template.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',
image: outputDir + 'images',
style: sassStyle
})
.on('error', gutil.log))
.pipe(gulp.dest(outputDir + 'css'))
.pipe(connect.reload())
});
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/js/*.json', ['json']);
gulp.watch('builds/development/images/**/*.*', ['images']);
});
gulp.task('connect', function() {
connect.server({
root: outputDir,
livereload: true
});
});
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('images', function() {
gulp.src('builds/development/images/**/*.*')
.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('json', function() {
gulp.src('builds/development/js/*.json')
.pipe(gulpif(env === 'production', jsonminify()))
.pipe(gulpif(env === 'production', gulp.dest('builds/production/js')))
.pipe(connect.reload())
});
gulp.task('default', ['html', 'json', 'coffee', 'js', 'compass', 'images', 'connect', 'watch']);