-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
87 lines (76 loc) · 2.31 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
"use strict";
const gulp = require('gulp');
const sourcemaps = require('gulp-sourcemaps');
const rename = require('gulp-rename');
const cssmin = require('gulp-cssmin');
const browserSync = require('browser-sync').create();
const del = require('del');
const buffer = require('vinyl-buffer');
const uglify = require('gulp-uglify');
const source = require('vinyl-source-stream');
const babelify = require('babelify');
const watchify = require('watchify');
const plumber = require('gulp-plumber');
const assign = require('lodash.assign');
const browserify = require('browserify');
const ghpages = require('gh-pages');
const path = require('path');
gulp.task("clean", function () {
return del("public");
});
gulp.task("styles", function () {
return gulp
.src("frontend/styles/**/*.css")
.pipe(sourcemaps.init())
.pipe(cssmin())
.pipe(rename({ suffix: ".min" }))
.pipe(sourcemaps.write())
.pipe(gulp.dest("public"));
});
gulp.task("assets", function () {
return gulp
.src("frontend/assets/**", { since: gulp.lastRun("assets") })
.pipe(gulp.dest("public"));
});
var customOpts = {
entries: ["./frontend/js/main.js"],
debug: true,
transform: [["babelify", { presets: ["es2015"] }]]
};
var opts = assign({}, watchify.args, customOpts);
var b = watchify(browserify(opts));
gulp.task("bundle", function () {
return b
.bundle()
.on("error", function (err) {
console.log(err.message);
browserSync.notify(err.message, 3000);
this.emit("end");
})
.pipe(plumber())
.pipe(source("app.js"))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(uglify())
.pipe(sourcemaps.write())
.pipe(gulp.dest("./public"));
});
gulp.task(
"build",
gulp.series("clean", gulp.parallel("styles", "assets", "bundle"))
);
gulp.task("watch", function () {
gulp.watch("frontend/assets/**/*.*", gulp.series("assets"));
gulp.watch("frontend/js/**/*.*", gulp.series("bundle"));
gulp.watch("frontend/styles/**/*.*", gulp.series("styles"));
});
gulp.task("serve", function () {
browserSync.init({
server: "public"
});
browserSync.watch("public/**/*.*").on("change", browserSync.reload);
});
gulp.task("dev", gulp.series("build", gulp.parallel("watch", "serve")));
gulp.task('deploy', function (cb) {
ghpages.publish(path.join(process.cwd(), 'public'), cb);
});