-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
executable file
·55 lines (47 loc) · 1.63 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
var gulp = require("gulp");
var gutil = require("gulp-util");
var notify = require("gulp-notify");
var source = require("vinyl-source-stream");
var buffer = require("vinyl-buffer");
var browserify = require("browserify");
var watchify = require("watchify");
var babelify = require("babelify");
var concat = require("gulp-concat");
var uglifycss = require("gulp-uglifycss");
var sass = require("gulp-sass");
var browserSync = require("browser-sync").create();
var ENTRY_FILE = "./src/js/index.js";
var OUTPUT_DIR = "./build/js";
var OUTPUT_FILE = "bundle.js";
var DELAY = 50;
gulp.task("browserify", function () {
var b = browserify({ entries: [ ENTRY_FILE ] }).transform(babelify);
function bundle() {
b.bundle()
.on("log", gutil.log)
.on("error", notify.onError())
.pipe(source(OUTPUT_FILE))
.pipe(buffer())
.pipe(gulp.dest(OUTPUT_DIR))
.pipe(browserSync.reload({ stream: true }));
}
watchify(b, { delay: DELAY }).on("update", bundle);
bundle();
});
gulp.task("serve", function () {
browserSync.init({
server: {
baseDir: "./build"
}
});
gulp.watch('./src/scss/*.scss', ['scss']);
gulp.watch(['./build/*.html', './build/css/*.css', './build/js/*.js']).on('change', browserSync.reload);
});
gulp.task('scss', function () {
return gulp.src('./src/scss/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(concat('build.css'))
.pipe(uglifycss())
.pipe(gulp.dest('./build/css/'));
});
gulp.task("default", [ "browserify", "serve" ]);