-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
88 lines (77 loc) · 2.56 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
var gulp = require('gulp'),
fs = require('fs'),
path = require('path'),
sass = require('gulp-ruby-sass'),
uglify = require('gulp-uglify'),
jshint = require('gulp-jshint'),
watch = require('gulp-watch'),
stringify = require('stringify'),
watchify = require('watchify'),
browserify = require('browserify'),
reactify = require('reactify'),
source = require('vinyl-source-stream'),
buffer = require('vinyl-buffer'),
colors = require('colors');
var files = ['app/src/**/*.js', '!app/src/vendor/**/*'];
gulp.task('sass', function () {
return sass('./app/styles/**/*.scss')
.pipe(gulp.dest('./app/build/styles'));
});
var bundle = function (bundler, filename) {
return function () {
console.log('writing [', colors.green(filename), ']');
return bundler.bundle()
// log errors if they happen
.on('error', function (error) {
console.error(error.message);
// console.error(error.filename, error.lineNumber)
})
.pipe(source(filename))
.pipe(gulp.dest('./app/build/src/'));
};
};
var bundler = watchify(browserify('./app/src/app.js', watchify.args));
// add any other browserify options or transforms here
bundler.transform(reactify)
.transform(stringify(['.html']));
gulp.task('browserify-watchify', bundle(bundler, 'bundle.js')); // so you can run `gulp js` to build the file
bundler.on('update', bundle(bundler, 'bundle.js')); // on any dep update, runs the bundler
bundler.on('log', console.log);
gulp.task('watch', function() {
// watch scss files
gulp.watch('app/styles/**/*.scss', ['sass']);
gulp.watch(files, ['jshint']);
});
gulp.task('browserify', function() {
return watchify(browserify('./app/src/app.js'), watchify.args)
// Register handlebars transform
.transform(hbsfy)
.transform(reactify)
.transform(stringify(['.html']))
.bundle()
//Pass desired output filename to vinyl-source-stream
.pipe(source('bundle.js'))
// Start piping stream to tasks!
.pipe(gulp.dest('./app/build/src/'));
});
gulp.task('browserify-minify', function() {
return browserify('./app/src/app.js')
// Register handlebars transform
.transform(reactify)
.transform(stringify(['.html']))
.bundle()
//Pass desired output filename to vinyl-source-stream
.pipe(source('bundle-minified.js'))
// minify
.pipe(buffer())
.pipe(uglify())
// Start piping stream to tasks!
.pipe(gulp.dest('./app/build/src/'));
});
gulp.task('jshint', function () {
gulp.src(files)
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('jshint-stylish'));
});
gulp.task('default', ['sass', 'browserify-watchify', 'watch']);
gulp.task('build', ['browserify-watchify', 'sass']);