This repository has been archived by the owner on Mar 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgulpfile.js
135 lines (111 loc) · 3.01 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
var gulp = require('gulp'),
concat = require('gulp-concat'),
streamify = require('gulp-streamify'),
uglify = require('gulp-uglify'),
source = require('vinyl-source-stream'),
browserify = require('browserify'),
less = require('gulp-less'),
minifycss = require('gulp-minify-css'),
nodemon = require('gulp-nodemon'),
clean = require('gulp-clean'),
exit = require('gulp-exit');
var bower_components = {
js: [
'./bower_components/angular/angular.js',
'./bower_components/angular-route/angular-route.js',
'./bower_components/emitter.js/emitter.js',
'./bower_components/klass/klass.js'
],
css: [
'./bower_components/bootstrap/css/bootstrap.css'
]
};
gulp.task('js', function () {
// Bower
gulp.src(bower_components.js)
.pipe(concat('bower.min.js'))
.pipe(uglify())
.pipe(gulp.dest('build'))
.on('end', livereload('.js'))
// Client
browserify('./app/client/client.js').on('error', function(err) {
console.log(err);
return err;
}).bundle()
.on('error', function (err) {
console.log(err);
return err;
})
.pipe(source('./app/client/client.js'))
.pipe(streamify(uglify()))
.pipe(streamify(concat('app.min.js')))
.pipe(gulp.dest('build'))
.on('end', livereload('.js'))
});
gulp.task('css', function () {
// Bower
gulp.src(bower_components.css)
.pipe(minifycss())
.pipe(concat('bower.min.css'))
.pipe(gulp.dest('build'))
.on('end', livereload('.css'))
// App
gulp.src('app/client/styles/app.less')
.pipe(less()).on('error', function (error) {
console.log(error.message);
return error;
})
.pipe(minifycss())
.pipe(concat('app.min.css'))
.pipe(gulp.dest('build'))
.on('end', livereload('.css'))
});
gulp.task('html', function () {
gulp.src('app/views/*.html')
.pipe(gulp.dest('build'))
.on('end', livereload('.html'))
});
gulp.task('images', function () {
gulp.src('app/client/images/*')
.pipe(gulp.dest('build'))
.on('end', livereload('.html'))
});
gulp.task('server', function () {
nodemon({
script: 'app/server/server.js',
ext: 'js',
ignore: ['gulpfile.js', 'scripts/*'],
env: {
'NODE_ENV': 'development'
}
}).on('error', function (error) {
return error;
});
});
gulp.task('clean', function () {
gulp.src(['./build'], { read: false })
.pipe(clean())
.pipe(exit());
});
var livereloadServer = null;
var livereload = function (_file) {
return function (_path) {
if (livereloadServer) livereloadServer.changed(_file);
}
}
gulp.task('watch', function() {
livereloadServer = require('gulp-livereload')();
gulp.watch(['app/**/*.js', 'bower_components/**/*.js'], ['js']);
gulp.watch(['app/**/*.less', 'bower_components/**/*.css'], ['css']);
gulp.watch(['app/**/*.html'], ['html']);
gulp.watch(['app/**/*.png', 'app/**/*.jpg'], ['images']);
});
gulp.task('run', [
'default',
'watch',
'server'
]);
gulp.task('build', [
'js', 'css', 'html', 'images',
]);
gulp.task('default', ['build']);