-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
84 lines (72 loc) · 1.87 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
const gulp = require("gulp");
const imagemin = require("gulp-imagemin");
const clean = require("gulp-clean");
const usemin = require("gulp-usemin");
const cssmin = require("gulp-cssmin");
const browserSync = require("browser-sync").create();
const jshint = require("gulp-jshint");
const jshintStylish = require("jshint-stylish");
const csslint = require("gulp-csslint");
const autoprefixer = require("gulp-autoprefixer");
const htmlmin = require("gulp-htmlmin");
const uglify = require("gulp-uglify-es").default;
gulp.task("build", ["clean"], () => {
gulp.start("build-img", "usemin");
});
gulp.task("copy", ["clean"], () =>
gulp.src("src/**/*").pipe(gulp.dest("public"))
);
gulp.task("clean", () => gulp.src("public").pipe(clean()));
gulp.task("build-img", () =>
gulp
.src("src/images/**/*")
.pipe(imagemin())
.pipe(gulp.dest("public/images"))
);
gulp.task("usemin", () =>
gulp
.src("src/index.html")
.pipe(
usemin({
html: [htmlmin({ collapseWhitespace: true })],
css: [cssmin, autoprefixer],
js: [uglify]
})
)
.on("error", err => {
console.log(err);
})
.pipe(gulp.dest("public"))
);
// prduction server
gulp.task("production", () => {
browserSync.init({
server: {
watch: false,
baseDir: "public"
}
});
});
// dev server
gulp.task("server", () => {
browserSync.init({
server: {
baseDir: "src"
}
});
gulp.watch("src/**/*").on("change", browserSync.reload);
gulp.watch("src/js/**/*.js").on("change", event => {
console.log("Linting " + event.path);
gulp
.src(event.path)
.pipe(jshint({ esnext: true }))
.pipe(jshint.reporter(jshintStylish));
});
gulp.watch("src/css/**/*.css").on("change", event => {
console.log("Linting " + event.path);
gulp
.src(event.path)
.pipe(csslint())
.pipe(csslint.reporter());
});
});