-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
122 lines (104 loc) · 3.94 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
var gulp = require('gulp');
var runSequence = require('run-sequence');
var del = require('del');
var mainBowerFiles = require('main-bower-files');
var browserSync = require('browser-sync');
var reload = browserSync.reload;
var $ = require('gulp-load-plugins')(['gulp-*']);
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
var config = {
src: 'app',
dist: 'dist',
environment: process.env.NODE_ENV
};
function isProduction() {
return config.environment === 'production';
}
function isDevelopment() {
return !isProduction();
}
gulp.plumbedSrc = function( ) {
return gulp.src.apply(gulp, arguments)
.pipe($.plumber({errorHandler: function(error) {
console.log(error);
this.emit('end');
}}));
};
gulp.task('font:bower', function() {
return gulp.plumbedSrc(mainBowerFiles({filter: '**/fonts/*'}))
.pipe(gulp.dest(config.dist + '/fonts'))
.pipe(reload({stream: true}));
});
gulp.task('css:bower', function() {
return gulp.plumbedSrc(mainBowerFiles({filter: '**/*.css'}))
.pipe($.if(isDevelopment(), $.sourcemaps.init()))
.pipe($.concat('vendor.css'))
.pipe($.if(isDevelopment(), $.sourcemaps.write()))
.pipe(gulp.dest(config.dist))
.pipe(reload({stream: true}));
});
gulp.task('css', function() {
return gulp.plumbedSrc([config.src + '/**/*.css'])
.pipe($.if(isDevelopment(), $.sourcemaps.init()))
.pipe($.concat('app.css'))
.pipe($.if(isDevelopment(), $.sourcemaps.write()))
.pipe(gulp.dest(config.dist))
.pipe(reload({stream: true}));
});
gulp.task('js:template', function() {
return gulp.plumbedSrc([config.src + '/**/*.html', '!' + config.src + '/index.html'])
.pipe($.if(isProduction(), $.minifyHtml()))
.pipe($.angularTemplatecache({module: 'app'}))
.pipe(gulp.dest(config.dist))
.pipe(reload({stream: true}));
});
gulp.task('js:bower', function() {
var filter = [
'**/*.js',
'!**/angular-mocks.js',
'!**/bootstrap*.js'
];
return gulp.plumbedSrc(mainBowerFiles({filter: filter}))
.pipe($.if(isDevelopment(), $.sourcemaps.init()))
.pipe($.concat('vendor.js'))
//.pipe($.if(isProduction(), $.uglify()))
.pipe($.if(isDevelopment(), $.sourcemaps.write()))
.pipe(gulp.dest(config.dist))
.pipe(reload({stream: true}));
});
gulp.task('js', function() {
return gulp.plumbedSrc([config.src + '/**/*.js', '!' + config.src + '/**/*.spec.js'])
.pipe($.angularFilesort())
.pipe($.jshint())
.pipe($.jshint.reporter('default'))
.pipe($.jscs())
.pipe($.if(isDevelopment(), $.sourcemaps.init()))
.pipe($.concat('app.js'))
.pipe($.if(isProduction(), $.uglify()))
.pipe($.if(isDevelopment(), $.sourcemaps.write()))
.pipe(gulp.dest(config.dist))
.pipe(reload({stream: true}));
});
gulp.task('html', function() {
return gulp.plumbedSrc([config.src + '/index.html'])
.pipe(gulp.dest(config.dist))
.pipe(reload({stream: true}));
});
gulp.task('clean', function(done) {
del([config.dist], done);
});
gulp.task('build', ['clean'], function(done) {
runSequence(['js:template', 'js:bower', 'js', 'css:bower', 'css', 'font:bower', 'html'], done);
});
gulp.task('watch', ['build'], function() {
gulp.watch([config.src + '/**/*.html', '!' + config.src + '/index.html'], ['js:template']);
gulp.watch(['bower.json'], ['css:bower', 'js:bower', 'font:bower']);
gulp.watch([config.src + '/**/*.js', '!' + config.src + '/**/*.spec.js'], ['js']);
gulp.watch([config.src + '/**/*.css'], ['css']);
gulp.watch([config.src + '/index.html'], ['html']);
});
gulp.task('serve', ['watch'], function() {
browserSync({
server: config.dist
});
});