-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
120 lines (103 loc) · 2.91 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
/*eslint-disable no-console */
const browserify = require('browserify');
const connect = require('gulp-connect');
const merge = require('merge-stream');
const notify = require('gulp-notify');
const gulp = require('gulp');
const gulpif = require('gulp-if');
const gutil = require('gulp-util');
const source = require('vinyl-source-stream');
const streamify = require('gulp-streamify');
const uglify = require('gulp-uglify');
const watchify = require('watchify');
const files = {
dependencies: [
'react',
'react-dom',
'react-addons-transition-group',
'react-addons-css-transition-group',
],
browserify: [
'./demo/main.js',
],
};
const browserifyTask = function (options) {
let bundler = browserify({
entries: [options.src],
transform: [
['babelify', {
presets: ['es2015', 'stage-2', 'react'],
plugins: ['transform-class-properties'],
}],
],
debug: options.development,
cache: {}, // Requirement of watchify
packageCache: {}, // Requirement of watchify
fullPaths: options.development,
alias: ['/node_modules/react/react.js:react'],
extensions: ['.js', '.jsx', '.json'],
});
const rebundle = function () {
const start = Date.now();
console.log('Building APP bundle');
return bundler
.bundle()
.on('error', gutil.log)
.pipe(source(options.output))
.pipe(gulpif(!options.development, streamify(uglify())))
.pipe(gulp.dest(options.dest))
.pipe(gulpif(options.development, connect.reload()))
.pipe(notify(function () {
console.log('APP bundle built in ' + (Date.now() - start) + 'ms');
}));
};
bundler.external(files.dependencies);
if (options.development) {
bundler = watchify(bundler);
bundler.on('update', rebundle);
}
return rebundle();
};
const browserifyDepsTask = function (options) {
const vendorsBundler = browserify({
debug: options.development,
require: files.dependencies,
});
const start = new Date();
console.log('Building VENDORS bundle');
return vendorsBundler
.bundle()
.on('error', gutil.log)
.pipe(source(options.output))
.pipe(gulpif(!options.development, streamify(uglify())))
.on('error', gutil.log)
.pipe(gulp.dest(options.dest))
.pipe(notify(function () {
console.log('VENDORS bundle built in ' + (Date.now() - start) + 'ms');
}));
};
gulp.task('demo', function() {
process.env.NODE_ENV = 'development';
const browserifyDepsOpt = {
development: true,
src: files.dependencies,
output: 'vendors.js',
dest: './demo/build/scripts',
};
const browserifyOpt = {
development: true,
src: files.browserify,
output: 'bundle.js',
dest: './demo/build/scripts',
};
const serverOpt = {
root: './demo',
port: 8080,
livereload: true,
};
connect.server(serverOpt);
return merge(
browserifyDepsTask(browserifyDepsOpt),
browserifyTask(browserifyOpt)
);
});