-
Notifications
You must be signed in to change notification settings - Fork 6
/
GulpFile.js
executable file
·105 lines (85 loc) · 2.66 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
var wiredep = require('wiredep'),
gulp = require('gulp'),
$ = require('gulp-load-plugins')({lazy:false});
var paths = {
root: './client',
html: './client/**/*.html',
bower: './client/bower_components',
index: './client/index.html',
styles: './client/app/**/*.css',
stylus: './client/app/**/*index.styl',
scripts: ['./client/app/**/*.js','!./client/app/**/*.spec.js'],
stylePath: './client/app/core/styles',
};
var tmp = {
root: './.tmp',
styles: './.tmp/**/*.css',
scripts: './.tmp/**/*.js'
};
gulp
.task('default', $.sequence( 'build', 'server', 'watch'))
.task('server', startServer)
.task('watch', startWatch)
gulp
.task('dist', $.sequence('build:dist'))
gulp
.task('build', $.sequence('styles', 'inject', 'bower'))
.task('styles', styles)
.task('inject', startInject)
.task('bower', bower)
gulp
.task('build:dist', $.sequence('styles:dist', 'inject:dist', 'bower'))
.task('styles:dist', stylesDist)
.task('inject:dist', startInjectDist)
.task('bower', bower)
function startServer(){
process.env.NODE_ENV = 'development';
require('./server');
// $.nodemon('./server/index')
}
function startWatch(){
$.livereload();
$.livereload.listen();
gulp.watch('./client/app/**/*.css', $.livereload.changed);
gulp.watch('./client/app/**/*.styl', ['styles', $.livereload.changed]);
gulp.watch('./client/app/**/*.js', $.livereload.changed);
gulp.watch('./client/**/*.html', $.livereload.changed);
}
function styles(){
return gulp.src( paths.stylus )
.pipe( $.stylus() )
.pipe( $.concat('app.css') )
.pipe( gulp.dest(tmp.root) );
}
function stylesDist(){
return gulp.src( paths.stylus )
.pipe( $.stylus() )
.pipe( $.concat('app.css') )
.pipe( gulp.dest(paths.stylePath) );
}
function startInject(){
var target = gulp.src( paths.index );
var scripts = gulp.src( paths.scripts, {read:false} );
var styles = gulp.src( tmp.styles, {read:false} );
return target
.pipe( $.inject( scripts, {relative:true}) )
.pipe( $.inject( styles, {relative:false, ignorePath:'.tmp'}) )
.pipe( gulp.dest( paths.root ) );
}
function startInjectDist(){
var target = gulp.src( paths.index );
var scripts = gulp.src( paths.scripts, {read:false} );
var styles = gulp.src( paths.styles, {read:false} );
return target
.pipe( $.inject( scripts, {relative:true}) )
.pipe( $.inject( styles, {relative:true}) )
.pipe( gulp.dest( paths.root ) );
}
function bower(){
var wire = wiredep.stream;
return gulp.src( paths.index )
.pipe( wire({
directory:paths.bower
}))
.pipe( gulp.dest( paths.root ) );
}