-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
137 lines (100 loc) · 2.96 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
'use strict';
var gulp = require('gulp');
var del = require('del');
var sass = require('gulp-sass');
var path = require('path');
// Load plugins
var $ = require('gulp-load-plugins')();
var browserify = require('browserify');
var source = require('vinyl-source-stream');
//Sass
gulp.task('sass', function () {
gulp.src('./app/styles/*.scss')
.pipe(sass())
.pipe(gulp.dest('dist/styles'));
});
// Scripts
gulp.task('scripts', function () {
return browserify('./app/scripts/app.js')
.bundle()
.pipe(source('app.js'))
.pipe(gulp.dest('dist/scripts'))
});
gulp.task('jade', function () {
return gulp.src('app/template/*.jade')
.pipe($.jade({ pretty: true }))
.pipe(gulp.dest('dist'));
})
// HTML
gulp.task('html', function () {
return gulp.src('app/*.html')
.pipe($.useref())
.pipe(gulp.dest('dist'))
.pipe($.size());
});
// Images
gulp.task('images', function () {
return gulp.src('app/images/**/*')
.pipe($.cache($.imagemin({
optimizationLevel: 3,
progressive: true,
interlaced: true
})))
.pipe(gulp.dest('dist/images'))
.pipe($.size());
});
gulp.task('jest', function () {
var nodeModules = path.resolve('./node_modules');
return gulp.src('app/scripts/**/')
.pipe($.jest({
scriptPreprocessor: nodeModules + '/gulp-jest/preprocessor.js',
unmockedModulePathPatterns: [nodeModules + '/react']
}));
});
// Clean
gulp.task('clean', function (cb) {
del(['dist/styles', 'dist/scripts', 'dist/images',
'dist/styles'], cb);
});
// Bundle
gulp.task('bundle', ['scripts', 'bower'], function(){
return gulp.src('./app/*.html')
.pipe($.useref.assets())
.pipe($.useref.restore())
.pipe($.useref())
.pipe(gulp.dest('dist'));
});
// Build
gulp.task('build', ['html', 'bundle', 'sass', 'images']);
// Default task
gulp.task('default', ['clean', 'build', 'jest' ]);
// Webserver
gulp.task('serve', function () {
gulp.src('dist')
.pipe($.webserver({
livereload: true,
host: '0.0.0.0',
port: 9000
}));
});
// Bower helper
gulp.task('bower', function() {
gulp.src('app/bower_components/**/*.js', {base: 'app/bower_components'})
.pipe(gulp.dest('dist/bower_components/'));
});
gulp.task('json', function() {
gulp.src('app/scripts/json/**/*.json', {base: 'app/scripts'})
.pipe(gulp.dest('dist/scripts/'));
});
// Watch
gulp.task('watch', ['html', 'bundle', 'serve'], function () {
// Watch .json files
gulp.watch('app/scripts/**/*.json', ['json']);
// Watch .html files
gulp.watch('app/*.html', ['html']);
// Watch .js files
gulp.watch('app/scripts/**/*.js', ['scripts', 'jest' ]);
gulp.watch('app/styles/**.scss', ['sass']);
// Watch image files
gulp.watch('app/images/**/*', ['images']);
});