-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
executable file
·104 lines (91 loc) · 2.46 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
var gulp = require('gulp');
var util = require('gulp-util');
var jade = require('gulp-jade');
var stylus = require('gulp-stylus');
var ks = require('kouto-swiss');
var browserify = require('browserify');
var babelify = require('babelify');
var source = require('vinyl-source-stream');
var changed = require('gulp-changed');
var uglify = require('gulp-uglify');
var buffer = require('vinyl-buffer');
var path = {
layouts: './src/layouts/**/*.jade',
jade: './src/**/*.jade',
stylus: './src/stylus/*.styl',
stylusAll: './src/stylus/**/*.styl',
scripts: './src/**/*.jsx',
bundleEntry: './src/app.jsx',
images: [
'./src/images/**/*.jpg',
'./src/images/**/*.png',
'./src/images/**/*.gif'
],
svg: './src/images/**/*.svg',
fonts: [
'./src/fonts/**/*.ttf',
'./src/fonts/**/*.svg',
'./src/fonts/**/*.eot',
'./src/fonts/**/*.woff'
],
dest: {
root: './www/',
css: './www/css/',
js: './www/js/',
img: './www/img',
fonts: './www/fonts'
}
};
gulp.task('compile:html', function() {
var locals = {
env: (process.env.NODE_ENV || 'development')
};
var jadeOpts = {
locals: locals
};
gulp.src([path.jade, '!'+path.layouts])
.pipe(jade(jadeOpts))
.pipe(gulp.dest(path.dest.root));
});
gulp.task('compile:css', function () {
gulp.src(path.stylus)
.pipe(stylus({
use: [ks()]
}))
.pipe(gulp.dest(path.dest.css));
});
gulp.task("compile:js", function () {
var t = browserify({
entries: path.bundleEntry,
extensions: ['.jsx'],
debug: (process.env.NODE_ENV === 'development'),
insertGlobals: true
})
.transform(babelify)
.bundle()
.pipe(source('bundle.js'));
if (process.env.NODE_ENV === 'production') {
t = t.pipe(buffer())
.pipe(uglify());
}
t = t.pipe(gulp.dest(path.dest.js));
});
gulp.task('compress:images', function() {
gulp.src(path.images)
.pipe(changed(path.dest.img))
.pipe(gulp.dest(path.dest.img));
});
gulp.task('copy:fonts', function() {
gulp.src(path.fonts)
.pipe(changed(path.dest.fonts))
.pipe(gulp.dest(path.dest.fonts));
});
gulp.task('build', ['compile:html', 'compile:css', 'compile:js', 'compress:images', 'copy:fonts']);
gulp.task('watch', function() {
gulp.watch(path.jade, ['compile:html']);
gulp.watch(path.stylusAll, ['compile:css']);
gulp.watch(path.scripts, ['compile:js']);
gulp.watch(path.images, ['compress:images']);
gulp.watch(path.fontes, ['copy:fonts']);
});
gulp.task('default', ['build', 'watch']);