-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
97 lines (82 loc) · 2.35 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
var gulp = require('gulp');
var gulpLoadPlugins = require('gulp-load-plugins');
var plugins = gulpLoadPlugins();
var del = require('del');
var browserSync = require('browser-sync');
gulp.task('jsonsrv', function() {
plugins.jsonSrv.start({
data: 'json-server/db.json',
port: 3000,
static: 'dist/'
});
});
gulp.task('jsonsrv:dev', function() {
plugins.jsonSrv.start({
data: 'json-server/db.json',
port: 3000,
static: './'
});
});
gulp.task('jshint', function() {
return gulp.src('app/scripts/**/*.js')
.pipe(plugins.plumber())
.pipe(plugins.jshint())
.pipe(plugins.jshint.reporter(plugins.stylish));
});
//Clean
gulp.task('clean', function() {
return del(['dist']);
});
gulp.task('usemin', ['jshint'], function() {
return gulp.src('./app/**/*.html')
.pipe(plugins.usemin({
css: [plugins.minifyCss(), plugins.rev()],
js: [plugins.ngAnnotate(), plugins.uglify(), plugins.rev()]
}))
.pipe(plugins.debug({title: 'usemin'}))
.pipe(gulp.dest('dist/'));
});
//Images
gulp.task('imagemin', function() {
return del(['dist/images']),
gulp.src('app/images/**/*')
.pipe(plugins.cache(plugins.imagemin({ optimizationLevel: 3, progressive: true, interlaced: true})))
.pipe(gulp.dest('dist/images'))
.pipe(plugins.log2('Images task complete'))
;
});
gulp.task('copyfonts', ['clean'], function() {
gulp.src('./bower_components/font-awesome/fonts/**/*.{ttf,woff,eof,svg}*')
.pipe(gulp.dest('./dist/fonts'));
gulp.src('./bower_components/bootstrap/dist/fonts/**/*.{ttf,woff,eof,svg}*')
.pipe(gulp.dest('./dist/fonts'));
});
//Watch
gulp.task('watch', function() { //gulp.task('watch', ['browser-sync'], function() {
gulp.start('jsonsrv');
gulp.watch(['app/scripts/**/*.js', 'app/styles/**/*.css', 'app/**/*.html'], ['usemin']);
gulp.watch(['app/images/**/*'], ['imagemin']);
});
gulp.task('dev', function() {
gulp.start('jsonsrv:dev');
});
gulp.task('browser-sync', ['default'], function() {
var files = [
'app/**/*.html',
'app/styles/**/*.css',
'app/images/**/*.png',
'app/scripts/**/*.js',
'dist/**/*'
];
browserSync.init(files, {
server: {
baseDir: 'dist',
index: 'index.html'
}
});
gulp.watch(['dist/**']).on('change', browserSync.reload);
});
//Default task
gulp.task('default', ['clean'], function() {
gulp.start('usemin', 'imagemin', 'copyfonts');
});