-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
77 lines (71 loc) · 2.22 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
'use strict';
var gulp = require('gulp');
var notify = require('gulp-notify');
// JSX Configuration
var browserify = require('browserify');
var babelify = require('babelify');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var watchify = require('watchify');
var reactify = require('reactify');
// Styles
var sass = require('gulp-ruby-sass');
var concat = require('gulp-concat');
gulp.task('default', ['styles'], function() {
gulp.watch('./demo/styles/*.scss', ['styles']);
return scripts(true);
});
gulp.task('styles', function() {
return sass('demo/styles/application.scss',{
style: 'expanded',
precision: 10,
loadPath: ['./bower_components/bootstrap-sass/assets/stylesheets']
// loadPath: ['./bower_components/bootstrap/less/']
})
.pipe(concat('main.css'))
.pipe(gulp.dest('demo/styles/'))
.pipe(notify({
title: 'Styles',
subtitle: 'Styles finished',
message: 'Styles finished',
onLast: true
}));
});
function scripts(watch) {
var bundler, rebundle, path;
path = './demo/scripts/';
bundler = browserify({
entries: './demo/scripts/application.js',
extensions: ['.js.jsx'],
debug: true,
cache: {}, // required for watchify
packageCache: {}, // required for watchify
fullPaths: watch // required to be true only for watchify
});
if(watch) {
bundler = watchify(bundler);
}
bundler.transform(reactify);
rebundle = function() {
var stream = bundler.bundle();
stream.on('error', handleErrors);
stream = stream.pipe(source('main.js'));
return stream.pipe(gulp.dest(path))
.pipe(notify({
title: 'Scripts',
subtitle: 'Transform finished',
message: 'Transform finished',
onLast: true
}));
};
bundler.on('update', rebundle);
return rebundle();
}
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
}