-
Notifications
You must be signed in to change notification settings - Fork 42
/
gulpfile.js
124 lines (108 loc) · 2.93 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
var gulp = require('gulp');
var sourcemaps = require('gulp-sourcemaps');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var browserify = require('browserify');
var watchify = require('watchify');
var babel = require('babelify');
var jade = require('gulp-jade');
var connect = require('gulp-connect');
var uglify = require('gulp-uglify');
var envify = require('envify/custom');
var file = require('gulp-file');
var buildDir = 'build';
var devBuildDir = 'dev_build';
function handleError(err) {
console.error(err); // eslint-disable-line no-console
this.emit('end');
}
function templates(outDir) {
return function() {
return gulp.src('public/*.jade')
.pipe(jade())
.pipe(gulp.dest(outDir));
};
}
function styles(outDir) {
return function() {
return gulp.src('public/*.css')
.pipe(gulp.dest(outDir))
.pipe(connect.reload());
};
}
function vendor(outDir) {
return function() {
return gulp.src('public/vendor/**')
.pipe(gulp.dest(outDir + '/vendor'));
};
}
function icons(outDir) {
return function() {
return gulp.src('public/icons/**')
.pipe(gulp.dest(outDir + '/icons'));
};
}
gulp.task('templates', templates(devBuildDir));
gulp.task('styles', styles(devBuildDir));
gulp.task('vendor', vendor(devBuildDir));
gulp.task('icons', icons(devBuildDir));
function compile(opts) {
var bundler = watchify(
browserify('./public/main.js', { debug: true })
.transform(babel)
.transform(envify({
NODE_ENV: 'development'
}), {global: true})
);
function rebundle() {
return bundler.bundle()
.on('error', handleError)
.pipe(source('main.js'))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(devBuildDir))
.pipe(connect.reload());
}
if (opts.watch) {
bundler.on('update', function() {
console.log('-> bundling...'); // eslint-disable-line no-console
return rebundle();
});
}
return rebundle();
}
gulp.task('connect', function() {
return connect.server({
root: devBuildDir,
livereload: true
});
});
gulp.task('watch', function() {
gulp.watch('public/*.css', ['styles']);
return compile({watch: true});
});
gulp.task('build', function() {
templates(buildDir)();
styles(buildDir)();
vendor(buildDir)();
icons(buildDir)();
file('CNAME', 'circuits.im', { src: true })
.pipe(gulp.dest(buildDir));
return browserify('./public/main.js')
.transform(envify({
NODE_ENV: 'production'
}), {global: true})
.transform(babel.configure({
optional: [
'optimisation.react.constantElements',
'optimisation.react.inlineElements'
]
}))
.bundle().on('error', handleError)
.pipe(source('main.js'))
.pipe(buffer())
.pipe(uglify())
.pipe(gulp.dest(buildDir));
});
gulp.task('default', ['templates', 'vendor', 'styles', 'icons', 'connect', 'watch']);