-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
105 lines (75 loc) · 2.41 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
100
101
102
103
104
105
var gulp = require('gulp');
var watch = require('gulp-watch');
var livereload = require('gulp-livereload');
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var fs = require('fs');
var del = require('del');
var gutil = require('gulp-util');
var targetLocation = './target/classes/static/js/react';
var REACT_FILES = [ './src/front-end/react/**/*.js'];
var streamify = require('gulp-streamify');
var uglify = require('gulp-uglify');
var pageURL = 'http://localhost:8000';
function Bundle() {
var Bundler = browserify({
entries: 'src/front-end/react/index.js',
transform: [["babelify", {"presets": ["es2015","react"]}]],
extensions: ['.js'],
debug: true,
cache: {},
packageCache: {},
fullPaths: true
});
return Bundler
.bundle()
.on('error', console.error);
}
gulp.task('react-build-dev', function () {
Bundle()
.pipe(source('bundle.js'))
.pipe(gulp.dest(targetLocation))
.on('finish', function ( ) {
gutil.log("build bundle end");
livereload.reload(pageURL);
});
;
});
gulp.task('react-build', function () {
function prodBundle()
{
var prodBundler = browserify({
entries: 'src/front-end/react/index.js',
transform: [["babelify", {"presets": ["es2015", "react"]}],
["envify", {NODE_ENV: 'production',
'global': true, '_': 'purge', }]],
extensions: ['.js'],
debug: true,
cache: {},
packageCache: {},
fullPaths: false
});
return prodBundler
.bundle()
.on('error', console.error);
}
prodBundle()
.pipe(source('bundle.js'))
.pipe(streamify(uglify()))
.pipe(gulp.dest(targetLocation ))
.on('finish', function ( ) {
gutil.log("finished release build");
});;
});
gulp.task('clean', function ( ) {
del([targetLocation+'/bundle.js']);
});
gulp.task('frontend-watch', function () {
watch(REACT_FILES, function (events, done) {
gulp.start('react-build-dev');
});
});
gulp.task('init-dev',['react-build-dev' ]);
gulp.task('dev',['frontend-watch' ]);
gulp.task('release',['react-build']);
gulp.task('default',['react-build']);