-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
99 lines (85 loc) · 2.39 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
var browserify = require('browserify');
var gulp = require('gulp');
var less = require('gulp-less');
var lessify = require('node-lessify');
var notify = require('gulp-notify');
var rename = require('gulp-rename');
var reactify = require('reactify');
var babelify = require('babelify');
var streamify = require('gulp-streamify');
var uglify = require('gulp-uglify');
var source = require('vinyl-source-stream');
var webserver = require('gulp-webserver');
// Define some paths.
var paths = {
app_js: ['./src/js/app.js'], // 'entry point'
js: ['./src/js/**/*.js'],
less_files: ['./src/style/style.less'],
build: './dist/',
style: './dist/style/',
src_style: './src/style/',
scripts: './src/js/',
src: './src/',
bundle: 'bundle.js'
};
// Our CSS task. It finds all our Less files and compiles them.
gulp.task('less', function() {
gulp.src(paths.less_files)
.pipe(less())
.pipe(gulp.dest(paths.style));
});
gulp.task('copy', function() {
gulp.src(paths.src + 'index.html').pipe(gulp.dest(paths.build));
gulp.src('assets/**/*').pipe(gulp.dest(paths.build + 'assets/'));
gulp.src(paths.src_style + 'default-theme/**/*').pipe(gulp.dest(paths.build + 'themes/default/'));
});
// Build
function buildJS(file) {
var props = {
entries: [file],
debug : true,
transform: [reactify, babelify, lessify]
};
var bundler = browserify(props);
function rebundle() {
var stream = bundler.bundle();
return stream
.on('error', catchErrors)
.pipe(source(file))
.pipe(streamify(uglify()))
.pipe(rename(paths.bundle))
.pipe(gulp.dest(paths.build));
}
return rebundle();
}
gulp.task('js', function() {
buildJS(paths.app_js[0])
});
function catchErrors() {
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
}
// Rerun tasks whenever a file changes.
gulp.task('watch', function() {
try {
gulp.watch(paths.less_files, ['less']);
gulp.watch(paths.js, ['js']);
} catch(e) {
console.log(e);
}
});
// Static server
gulp.task('serve', function() {
gulp.src('dist')
.pipe(webserver({
port: 8080,
host: '0.0.0.0'
}));
});
gulp.task('default', ['watch', 'js', 'less', 'copy', 'serve']);
gulp.task('build', ['js', 'less', 'copy']);
gulp.task('server', ['serve']);