forked from nramirez/gulp_browserify_es6_babel_react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
77 lines (67 loc) · 1.66 KB
/
gulpfile.babel.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
'use strict';
import source from 'vinyl-source-stream';
import gulp from 'gulp';
import browserify from 'browserify';
import babelify from 'babelify';
import run from 'run-sequence';
import rimraf from 'rimraf';
import shell from 'gulp-shell';
import server from 'gulp-live-server';
import babel from 'gulp-babel';
const paths = {
src: './src',
publicSrc: './public/js',
dest: './app',
bundle: 'bundle.js',
bundleDest: './app/public/js',
mainJs: './public/js/index'
};
//Catch the server instance
let express;
gulp.task('default', cb => {
run('server', 'build', 'watch', cb);
});
gulp.task('build', cb =>{
run('clean', 'babel', 'client', 'restart', cb);
});
//build when a file has changed
gulp.task('watch', cb => {
gulp.watch([
`${paths.src}/**.js`,
`${paths.publicSrc}/**.jsx`
], ['build']);
});
/*
Server
*/
gulp.task('server', () => {
express = server.new(paths.dest);
});
gulp.task('restart', () =>{
express.start.bind(express)();
});
//Clean the app destination, to prepare for new files
gulp.task('clean', cb => {
rimraf(paths.dest, cb);
});
//Transform back-end ES6 to ES5
//only transform features not supported by node v5
gulp.task('babel', cb => {
return gulp.src(`${paths.src}/**/*.js`)
.pipe(babel({
presets: ['es2015-node5', 'stage-0']
}))
.pipe(gulp.dest(paths.dest));
});
/*
Client
*/
//Transform client ES6 to ES5
//With react support
gulp.task('client', cb => {
return browserify({entries: paths.mainJs, extensions: ['.jsx'], debug: true})
.transform('babelify', {presets: ['es2015', 'react']})
.bundle()
.pipe(source(paths.bundle))
.pipe(gulp.dest(paths.bundleDest));
});