-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
100 lines (85 loc) · 2.17 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import babelify from 'babelify';
import browserify from 'browserify';
import buffer from 'vinyl-buffer';
import del from 'del';
import gulp from 'gulp';
import gulpif from 'gulp-if';
import source from 'vinyl-source-stream';
import uglify from 'gulp-uglify';
import util from 'gulp-util';
import browserSync from 'browser-sync';
const reload = browserSync.reload;
const config = {
filename: 'app',
scripts: {
input: ['./src/app.js'],
out: 'dist/',
watch: ['./src/**/*.js']
},
isDev : util.env.dev // Config is dev if the dev flag is passed (gulp --dev)
};
/**
* Deletes the /dist/ folder
*/
gulp.task('clean', () => {
del(config.scripts.out);
});
/**
* Builds all of our scripts
*/
gulp.task('scripts', () => {
// console.log(CONFIG)
const entries = config.scripts.input;
entries.map( (entry) => {
// Browserfy Object
const bundler = browserify({
entries: entry,
debug: config.isDev
});
// Transform through Babel
bundler.transform( 'babelify', {
presets: ['es2015']
});
return bundler.bundle().on('error', (err) => {
console.error(err);
this.emit('end');
})
// Convert Stream to buffer
.pipe(source(config.filename + '.js'))
.pipe(buffer())
// if not dev, uglify the code
.pipe(gulpif(!config.isDev, uglify()))
.pipe(gulp.dest(config.scripts.out))
.pipe(reload({stream:true}));
});
});
gulp.task('browser-sync', () => {
//watch files
const files = [
'./assets/styles/style.css',
'./**/*.php'
];
//initialize browsersync
browserSync.init(files, {
server: {
baseDir: "./"
}
});
});
/**
* Watches for changes and calls the correct task
*/
gulp.task('watch', ['scripts', 'browser-sync'], () => {
gulp.watch(config.scripts.watch, ['scripts']);
});
/**
* Our Default task gets executed when calling gulp.
*/
gulp.task('default', ['clean'], () => {
if (config.isDev) {
gulp.start('watch');
}
else {
gulp.start('scripts');
}
});