forked from patronage/donate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
executable file
·90 lines (80 loc) · 2.45 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
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var rimraf = require('rimraf');
var runSequence = require('run-sequence');
var source = require('vinyl-source-stream');
var sourcemaps = require('gulp-sourcemaps');
var browserify = require('browserify');
var reactify = require('reactify');
var browserSync = require('browser-sync');
var reload = browserSync.reload;
var handleErrors = function() {
var args = Array.prototype.slice.call(arguments);
$.notify.onError({
title: 'Compile Error',
message: '<%= error.message %>'
}).apply(this, args);
this.emit('end');
}
gulp.task('styles', function() {
return gulp.src( 'styles/screen.scss' )
.pipe(sourcemaps.init())
.pipe($.sass({
style: 'compressed',
onError: function(err){
$.notify().write(err);
}
}))
.pipe($.sourcemaps.write())
.pipe($.autoprefixer('last 2 versions'))
.pipe(gulp.dest( 'dist/stylesheets' ))
});
gulp.task('browserify', function() {
var self = this;
var b = browserify({
entries: './templates/app.jsx'
})
b.transform(reactify); // use the reactify transform
return b.bundle()
.on('error', handleErrors)
.pipe(source('templates/app.jsx'))
.pipe($.rename('app.js'))
.pipe(gulp.dest('./dist'));
});
// clean output directory
gulp.task('clean', function (cb) {
rimraf('dist', cb);
});
gulp.task('assetMover', function() {
gulp.src('assets/**')
.pipe(gulp.dest('dist/assets'))
});
gulp.task('viewMover', function() {
gulp.src('index.html', {base: './'})
.pipe(gulp.dest('dist/'))
});
gulp.task('webserver', function() {
browserSync({
// tunnel: true,
logLevel: 'info',
files: 'dist/stylesheets/screen.css',
injectChanges: true,
server: {
baseDir: ['dist'],
}
});
});
gulp.task('watch', function() {
gulp.watch([
'dist/app.js',
'dist/assets/**/*',
'dist/index.html'
], reload);
gulp.watch('assets/**/*', ['assetMover']);
gulp.watch('index.html', ['viewMover']);
gulp.watch('{components,data,library,templates}/**/*.{js,jsx,json}', ['browserify']);
gulp.watch('styles/**/*.scss', ['styles']);
});
gulp.task('default', function( cb ) {
runSequence( 'clean', 'viewMover', 'assetMover', 'styles', 'browserify', ['watch', 'webserver'], cb );
});