forked from AdeleD/react-paginate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
79 lines (65 loc) · 1.88 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
'use strict';
var fs = require('fs');
var path = require('path');
var util = require('util');
var gulp = require('gulp');
var browserify = require('browserify');
var reactify = require('reactify');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var uglify = require('gulp-uglify');
var nodemon = require('gulp-nodemon');
var CONFIG = {
sample: {
files: {
data: path.join(__dirname, 'sample', 'data.json'),
assets: [
'sample/**/*.html',
'sample/**/*.css',
'sample/**/*.js'
]
}
}
};
gulp.task('generate:data', function(cb) {
var comments = [];
for (var i = 0; i < 200; i++) {
comments.push({
username : util.format('user-%s', i),
comment : util.format('This is the comment #%d', i)
});
}
fs.writeFileSync(CONFIG.sample.files.data, JSON.stringify(comments, null, 2));
return cb();
});
gulp.task('watch', function() {
gulp.watch('./react_components/*.js', ['app', 'sample']);
gulp.watch('./sample/sample.jsx', ['sample']);
});
gulp.task('app', function() {
return browserify('./react_components/index.js')
.transform(reactify)
.bundle()
.pipe(source('react-paginate.js'))
.pipe(buffer())
.pipe(uglify())
.pipe(gulp.dest('./build'));
});
gulp.task('sample', function() {
return browserify('./sample/sample.jsx')
.transform(reactify)
.bundle()
.pipe(source('sample.js'))
.pipe(buffer())
.pipe(gulp.dest('./sample'));
});
gulp.task('server:watch', function () {
nodemon({script: 'server.js'})
.on('restart', 'server:reload');
});
gulp.task('server:reload', function() {
gulp.watch('./react_components/*.js', ['app', 'sample']);
gulp.watch('./sample/sample.jsx', ['sample']);
});
gulp.task('serve', ['app', 'sample', 'generate:data', 'server:watch']);
gulp.task('default', ['app', 'sample']);