-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
73 lines (60 loc) · 1.86 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
var gulp = require('gulp');
var gutil = require('gulp-util');
var concat = require('gulp-concat');
var inline = require('gulp-inline');
var source = require('vinyl-source-stream');
var babelify = require('babelify');
var watchify = require('watchify');
var exorcist = require('exorcist');
var browserify = require('browserify');
var browserSync = require('browser-sync').create();
// Input file.
watchify.args.debug = true;
var bundler_js = watchify(browserify(['./app/js/app.js'], watchify.args));
// Babel transform
bundler_js.transform(babelify.configure({
sourceMapRelative: 'app/js',
presets: ["es2015", "react"]
}));
// On updates recompile
bundler_js.on('update', bundle_js);
function bundle_js() {
gutil.log('Compiling JS...');
return bundler_js.bundle()
.on('error', function (err) {
gutil.log(err.message);
browserSync.notify("Browserify Error!");
this.emit("end");
})
.pipe(exorcist('app/dist/js/bundle.js.map'))
.pipe(source('bundle.js'))
.pipe(gulp.dest('./app/dist/js'))
.pipe(browserSync.stream({once: true}));
}
/**
* Gulp task alias
*/
gulp.task('bundle', function () {
return bundle_js();
});
gulp.task('css', function () {
return gulp.src(['app/css/main.css'])
.pipe(concat('main.css'))
.pipe(gulp.dest('app/dist/css'))
.pipe(browserSync.stream({once: true}));
});
gulp.task('html', function () {
return gulp.src(['app/index.html'])
.pipe(concat('index.html'))
.pipe(gulp.dest('app/dist'))
.pipe(browserSync.stream({once: true}));
});
/**
* First bundle, then serve from the ./app directory
*/
gulp.task('default', ['bundle','css','html'], function () {
browserSync.init({
server: "./app/dist"
});
gulp.watch('app/css/main.css', ['css']);
});