-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
78 lines (52 loc) · 1.77 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
var gulp = require('gulp');
var browserify = require('browserify');
var babelify = require('babelify');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var gp_uglify = require('gulp-uglify');
var sass = require('gulp-sass');
var minifycss = require('gulp-minify-css');
var concatCss = require('gulp-concat-css');
var merge = require('merge-stream');
var glob = require('glob');
var path = require('path');
//var nodemon = require('gulp-nodemon');
gulp.task('sass', function(){
return gulp.src('./resources/react/**/*.scss')
.pipe(sass()) // Converts Sass to CSS with gulp-sass
.pipe(concatCss('main.css'))
.pipe(minifycss())
.pipe(gulp.dest('public/assets/css/'))
});
gulp.task('build', function () {
var files = glob.sync('./resources/react/**/*.jsx');
return merge(files.map(function(file) {
let newpath = "public/assets/js/" +
path.relative('./resources/react/src', path.dirname(file));
//console.log(newpath);
return browserify({
entries: file,
debug: true
}).transform(babelify, {presets: ["es2015", "react", "stage-2"]})
.bundle()
.pipe(source(path.basename(file, '.jsx') + ".js"))
.pipe(gulp.dest(newpath))
}));
});
gulp.task('watch', ['build', 'sass'], function () {
let watcher = gulp.watch(['./resources/react/scenes/home/*.scss', './resources/react/scenes/home/*.jsx']);
function runTask(e) {
console.log(e.path);
if(e.path.endsWith('.jsx')) {
return gulp.start('build')
}
else if(e.path.endsWith('.scss')) {
return gulp.start('sass')
}
}
watcher.on('add', (event) => runTask(event))
watcher.on('unlink', (event) => runTask(event))
watcher.on('change', (event) => runTask(event))
return watcher;
});
gulp.task('default', ['watch']);