-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
147 lines (131 loc) · 3.96 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
var gulp = require('gulp');
var gutil = require('gulp-util');
var watch = require('gulp-watch');
var browserSync = require('browser-sync').create();
var source = require('vinyl-source-stream'); // Used to stream bundle for further handling etc.
var browserify = require('browserify');
var watchify = require('watchify');
var reactify = require('reactify');
var notify = require('gulp-notify');
var config = {
//sassPath: './resources/sass',
bowerDir: './bower_components'
};
function handleErrors() {
var args = Array.prototype.slice.call(arguments);
notify.onError({
title: 'Compile Error',
message: '<%= error.message %>'
}).apply(this, args);
this.emit('end'); // Keep gulp from hanging on this task
}
function buildScript(file, watch) {
var props = {
entries: ['./app/' + file],
debug : true,
transform: [reactify]
};
// watchify() if watch requested, otherwise run browserify() once
var bundler = watch ? watchify(browserify(props)) : browserify(props);
function rebundle() {
var stream = bundler.bundle();
return stream
.on('error', handleErrors)
.pipe(source(file))
.pipe(gulp.dest('./build/'));
}
// listen for an update and run rebundle
bundler.on('update', function() {
rebundle();
gutil.log('Rebundle...');
});
// run it once the first time buildScript is called
return rebundle();
}
// run once
gulp.task('scripts', function() {
return buildScript('main.js', false);
});
// Start a webserver at localhost:3000
gulp.task('server', function() {
browserSync.init({
server: {
baseDir: "./build"
}
});
gulp.watch('./build/*.*').on('change', browserSync.reload);
});
// run 'scripts' task first, then watch for future changes
gulp.task('default', ['scripts', 'server'], function() {
return buildScript('main.js', true);
});
//
// gulp.task('browserify', function() {
// var bundler = browserify({
// entries: ['./app/main.js'], // Only need initial file, browserify finds the deps
// transform: [reactify], // We want to convert JSX to normal javascript
// debug: true, // Gives us sourcemapping
// cache: {}, packageCache: {}, fullPaths: true // Requirement of watchify
// });
// var watcher = watchify(bundler);
//
// return watcher
// .on('update', function () { // When any files update
// var updateStart = Date.now();
// console.log('Updating!');
// watcher.bundle() // Create new bundle that uses the cache for high performance
// .on('error', handleErrors)
// .pipe(source('main.js'))
// // This is where you add uglifying etc.
// .pipe(gulp.dest('./build/'));
// console.log('Updated!', (Date.now() - updateStart) + 'ms');
// })
//
//
// var props = {
// entries: ['./scripts/' + file],
// debug : true,
// transform: [babelify, reactify]
// };
//
// // watchify() if watch requested, otherwise run browserify() once
// var bundler = watch ? watchify(browserify(props)) : browserify(props);
//
// function rebundle() {
// var stream = bundler.bundle();
// return stream
// .on('error', handleErrors)
// .pipe(source(file))
// .pipe(gulp.dest('./build/'));
// }
//
// // listen for an update and run rebundle
// bundler.on('update', function() {
// rebundle();
// gutil.log('Rebundle...');
// });
//
// // run it once the first time buildScript is called
// return rebundle();
// });
//
//
// // Start a webserver at localhost:3000
// gulp.task('server', function() {
// browserSync.init({
// server: {
// baseDir: "./build"
// }
// });
//
// gulp.watch('./build/*.*').on('change', browserSync.reload);
// });
//
// gulp.task('watch', function() {
// gulp.watch('js/*.js', ['lint', 'scripts']);
// gulp.watch('scss/*.scss', ['sass']);
// });
//
// //, 'lint', 'sass', 'scripts', 'watch'
//
// gulp.task('default', ['browserify', 'server']);