-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
41 lines (34 loc) · 1.22 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
var gulp = require('gulp');
var sourcemaps = require('gulp-sourcemaps');
var babel = require('gulp-babel');
var concat = require('gulp-concat');
var browserSync = require('browser-sync').create(); //creates the browser-sync instance
gulp.task("js", function(){
return gulp.src('src/**/*.js')
.pipe(sourcemaps.init())
.pipe(babel())
.pipe(concat('app.js'))
.pipe(sourcemaps.write("."))
.pipe(gulp.dest("dist"));
});
// create a task that ensures the `js` task is complete before
// reloading browsers
gulp.task('js-watch', ['js'], browserSync.reload);
gulp.task('html-watch', ['copy-index-html'], browserSync.reload);
gulp.task('copy-index-html', function(){
gulp.src('./src/index.html')
.pipe(gulp.dest('./dist'))
});
// use default task to launch Browsersync and watch JS files
gulp.task('serve', ['js','copy-index-html'], function () {
// Serve files from the root of this project
browserSync.init({
server: {
baseDir: "dist/"
}
});
// add browserSync.reload to the tasks array to make
// all browsers reload after tasks are complete.
gulp.watch("src/**/*.js", ['js-watch']);
gulp.watch("src/**/*.html", ['html-watch']);
});