-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGulpfile.js
117 lines (101 loc) · 2.47 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
/**
* Gulpfile
* Copyright (c) 2014 Crip.io
*/
/*-------------------------------------------------------------------
Required plugins
-------------------------------------------------------------------*/
var
gulp = require("gulp"),
concat = require("gulp-concat"),
header = require("gulp-header"),
browserSync = require("browser-sync"),
reload = browserSync.reload,
nodemon = require("gulp-nodemon")
stylus = require("gulp-stylus"),
uglify = require("gulp-uglify"),
package = require("./package.json");
// Banner using meta data from package.json
var banner = [
'/*!\n' +
' * <%= package.name %>\n' +
' * <%= package.description %>\n' +
' * <%= package.url %>\n' +
' * @author <%= package.author %>\n' +
' * @version <%= package.version %>\n' +
' * Copyright ' + new Date().getFullYear() + '. <%= package.license %> licensed.\n' +
' */',
'\n'
].join('');
// Project paths
var paths = {
src: {
css: './public/style/',
js: './public/js/',
html: './views/',
},
dist: {
css: './public/dist/',
js: './public/dist/',
html: './views/'
}
};
// Minify and concat css
gulp.task('stylus', function() {
gulp.src(paths.src.css + 'master.styl')
.on('error', function(err) {
console.log(err.message);
})
.pipe(stylus({
compress: true
}))
.pipe(header(banner, {
package: package
}))
.pipe(concat('master.min.css'))
.pipe(gulp.dest(paths.dist.css))
.pipe(reload({
stream: true,
}));
});
// Concatinate and minify Javascript
gulp.task('js', function() {
gulp.src([
paths.src.js + 'main.js'
])
.pipe(concat('main.min.js'))
.pipe(uglify())
.pipe(header(banner, {
package: package
}))
.pipe(gulp.dest(paths.dist.js))
.pipe(reload({
stream: true,
}));
});
gulp.task('browser-sync', ['nodemon'], function() {
browserSync.init(null, {
proxy: {
proxy: "localhost:3333",
notify: false
}
});
});
// Browser sync reload
gulp.task('bs-reload', function() {
browserSync.reload();
});
gulp.task('default', ['stylus', 'js', 'browser-sync'], function () {
gulp.watch([paths.src.css + '*.styl'], ['stylus', 'bs-reload']);
gulp.watch([paths.src.js + '*.js'], ['js', 'bs-reload']);
gulp.watch([paths.src.html + '*.jade'], ['bs-reload']);
});
gulp.task('nodemon', function (cb) {
var called = false;
return nodemon({script: 'server.js'}).on('start', function () {
if (!called) {
called = true;
cb();
}
});
});