-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgulpfile.js
More file actions
109 lines (93 loc) · 2.84 KB
/
gulpfile.js
File metadata and controls
109 lines (93 loc) · 2.84 KB
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
106
107
108
109
var gulp = require('gulp');
var uglify = require('gulp-uglify');
var htmlreplace = require('gulp-html-replace');
var source = require('vinyl-source-stream');
var browserify = require('browserify');
var watchify = require('watchify');
var reactify = require('reactify');
var streamify = require('gulp-streamify');
var sftp = require('gulp-sftp');
//used for restarting the server upon change in our server file
var nodemon = require('gulp-nodemon');
//used for refreshing the browser upon change in specified files
//as of v0.0.1 this modules has not been used in the gulpfile
var notify = require('gulp-notify');
var livereload = require('gulp-livereload');
//More seemless Gulp Task Management
var path = {
HTML: './client/index.html',
MINIFIED_OUT: 'build.min.js',
OUT: 'build.js',
DEST: 'dist',
DEST_BUILD: 'dist/build',
DEST_SRC: 'dist/src',
ENTRY_POINT: './client/src/mainview.jsx'
};
gulp.task('copy', function(){
gulp.src(path.HTML)
.pipe(gulp.dest(path.DEST));
});
//Watches for any changes in our JSX files to javascript
gulp.task('watch', function(){
gulp.watch(path.HTML, ['copy'])
var watcher = watchify(browserify({
entries: [path.ENTRY_POINT],
transform: [reactify],
debug: true,
cache: {}, packageCache: {}, fullPaths: true
}));
return watcher.on('update', function(){
watcher.bundle()
.pipe(source(path.MINIFIED_OUT))
.pipe(gulp.dest(path.DEST_BUILD))
console.log('Updated Minified Source Build');
})
.bundle()
.pipe(source(path.MINIFIED_OUT))
.pipe(streamify(uglify(path.MINIFIED_OUT)))
.pipe(gulp.dest(path.DEST_BUILD))
})
//Concatenates and Minifies our JS files
//concates all JSX files, renames it then saves it in the dist folder
gulp.task('build', function(){
browserify({
entries: [path.ENTRY_POINT],
transform: [reactify]
})
.bundle()
.pipe(source(path.MINIFIED_OUT))
.pipe(streamify(uglify(path.MINIFIED_OUT)))
.pipe(gulp.dest(path.DEST_BUILD))
console.log('One moment creating minified source build');
browserify({
entries: [path.ENTRY_POINT],
transform: [reactify]
})
.bundle()
.pipe(source(path.OUT))
.pipe(gulp.dest(path.DEST_SRC))
console.log('One moment creating source build');
});
//restarts the server whenever there is any change on server/server.js
gulp.task('nodemon', function(){
console.log('in nodemon')
nodemon({
script: './server/server.js',
ext: 'js',
// tasks: [],
env: {'NODE_ENV': 'development'}
})
.on('start', function(){
console.log('Server Started!!!');
})
.on('restart', function(){
console.log('Server Restarted!!!');
})
});
gulp.task('finished', function(){
console.log('Your production code was successfully built')
})
//Default Gulp tasks
gulp.task('default', ['copy', 'watch', 'nodemon']);
//Run Production tasks
gulp.task('production', ['copy', 'build', 'finished']);