-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
106 lines (93 loc) · 3.03 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
var gulp = require('gulp'),
gutil = require('gulp-util'),
coffee = require('gulp-coffee'),
browserify = require('gulp-browserify'),
compass = require('gulp-compass'),
cssNano = require('gulp-cssnano'),
connect = require('gulp-connect'),
gulpif = require('gulp-if'),
uglify = require('gulp-uglify'),
htmlMin = require('gulp-htmlmin'),
jsonMin = require('gulp-jsonminify'),
imageMin = require('gulp-imagemin'),
pngQuant= require('imagemin-pngquant'),
concat = require('gulp-concat');
var env,
coffeeSources,
jsSources,
sassSources,
htmlSources;
env = process.env.NODE_ENV || 'development';
if (env === 'development'){
outputDir = 'builds/development/';
} else {
outputDir = 'builds/production/';
}
coffeeSources = 'components/coffee/*.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';
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'
}))
.on('error', gutil.log)
.pipe(gulpif(env === 'production', cssNano()))
.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/images/**/*.*', ['images']);
gulp.watch('builds/development/js/*.json', ['json']);
});
gulp.task('connect', function () {
connect.server({
port: 4000,
root: outputDir,
livereload: true
})
});
gulp.task('html', function () {
gulp.src('builds/development/*.html')
.pipe(gulpif(env === 'production', htmlMin({
collapseWhitespace: true
})))
.pipe(gulpif(env === 'production', gulp.dest(outputDir)))
.pipe(connect.reload());
});
gulp.task('json', function () {
gulp.src('builds/development/js/*.json')
.pipe(connect.reload())
.pipe(gulpif(env === 'production', jsonMin()))
.pipe(gulpif(env === 'production', gulp.dest('builds/production/js')));
});
gulp.task('images', function () {
gulp.src('builds/development/images/**/*.*')
.pipe(gulpif(env === 'production', imageMin({
progressive: true,
svgoPlugins: [{ removeViewBox: false }],
use: [ pngQuant() ]
})))
.pipe(gulpif(env === 'production', gulp.dest(outputDir + 'images')))
.pipe(connect.reload());
});
gulp.task('default', ['html', 'json', 'coffee', 'js', 'compass', 'images', 'connect', 'watch']);