forked from benhowell/react-grid-gallery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
129 lines (110 loc) · 3.64 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
'use strict';
var gulp = require('gulp');
var ghPages = require('gulp-gh-pages');
var babelify = require('babelify');
var browserify = require('browserify');
var watchify = require('watchify');
var uglify = require('gulp-uglify');
var beautify = require('gulp-beautify');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var gulpif = require('gulp-if');
var runSequence = require('run-sequence');
var clean = require('gulp-clean');
const babel = require('gulp-babel');
gulp.task('default', function() {
gulp.start('build-all');
});
gulp.task('build-all', function() {
runSequence(
'clean-lib',
'build-lib',
'build-cljs-lib',
'clean-web',
['browserify', 'copy-css', 'copy-html'],
'deploy-web');
});
gulp.task('clean-lib', function () {
return gulp.src('./lib', {read: false})
.pipe(clean());
});
gulp.task('build-lib', function() {
return gulp.src(['src/**/*.js',
'!./src/require.js',
'!./src/react-grid-gallery.bundle.js'])
.pipe(babel({
presets: ['es2015', 'react']
}))
.pipe(gulp.dest('lib'));
});
gulp.task('clean-web', function () {
return gulp.src('./examples/dist', {read: false})
.pipe(clean());
});
gulp.task('deploy-web', function() {
return gulp.src('./examples/dist/**/*')
.pipe(ghPages());
});
gulp.task('copy-css', function () {
return gulp.src('./examples/**/*.css')
.pipe(gulp.dest('./examples/dist/css'));
});
gulp.task('copy-html', function () {
return gulp.src('./examples/index.html')
.pipe(gulp.dest('./examples/dist/'));
});
//uncomment watchify + on update for continuous build
gulp.task('browserify', function() {
var bundle =
//watchify(
browserify(['./examples/app.js',
'./examples/demo1.js',
'./examples/demo2.js',
'./examples/demo3.js',
'./examples/demo4.js',
'./examples/demo5.js',
'./examples/demo6.js'], {
extensions: ['.js', '.jsx']
})
//)
;
bundle.transform(babelify, {'presets': ['es2015', 'react']});
//bundle.on('update', function() {
// rebundle(bundle);
//});
function rebundle(bundle) {
return bundle.bundle()
.on('error', function(error) {
console.log(error.stack, error.message);
this.emit('end');
})
.pipe(gulpif((process.env.NODE_ENV == 'dev'), source('bundle.js'), source('bundle.min.js')))
.pipe(buffer())
.pipe(gulpif((process.env.NODE_ENV == 'dev'), beautify(), uglify()))
.pipe(gulp.dest('examples/dist/js'));
}
return rebundle(bundle);
});
gulp.task('build-cljs-lib', function() {
var bundle = browserify('./src/require.js', {
extensions: ['.js', '.jsx'],
});
bundle.transform(babelify, {'presets': ['es2015', 'react']});
bundle.on('update', function() {
rebundle(bundle);
});
function rebundle(bundle) {
return bundle.bundle()
.on('error', function(error) {
console.log(error.stack, error.message);
this.emit('end');
})
.pipe(gulpif((process.env.NODE_ENV == 'dev'),
source('react-grid-gallery.bundle.js'),
source('react-grid-gallery.bundle.min.js')))
.pipe(buffer())
.pipe(gulpif((process.env.NODE_ENV == 'production'), uglify()))
.pipe(gulp.dest('lib'));
}
return rebundle(bundle);
});