-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
65 lines (57 loc) · 1.73 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
const autoprefixer = require("autoprefixer");
const browserSync = require("browser-sync");
const cssnano = require("cssnano");
const del = require("del");
const gulp = require("gulp");
const gulpIf = require("gulp-if");
const htmlmin = require("gulp-htmlmin");
const imagemin = require("gulp-imagemin");
const postcss = require("gulp-postcss");
const runSequence = require("run-sequence");
const sourcemaps = require("gulp-sourcemaps");
const useref = require("gulp-useref");
gulp.task("browserSync", function() {
browserSync({ server: { baseDir: "src" } });
});
gulp.task("watch", function() {
gulp.watch(["*.html", "scripts/**/*.js"], { cwd: "src" }, browserSync.reload);
gulp.watch("src/stylesheets/**/*.css", function() {
return gulp
.src("src/stylesheets/**/*.css")
.pipe(browserSync.reload({ stream: true }));
});
});
gulp.task("useref", function() {
return gulp
.src("src/*.html")
.pipe(useref())
.pipe(gulp.dest("dist"));
});
gulp.task("html", function() {
return gulp
.src("dist/**/*.html")
.pipe(htmlmin({ collapseWhitespace: true }))
.pipe(gulp.dest("dist"));
});
gulp.task("css", function() {
const plugins = [autoprefixer({ cascade: false }), cssnano()];
return gulp
.src("dist/**/*.css")
.pipe(sourcemaps.init())
.pipe(postcss(plugins))
.pipe(sourcemaps.write("."))
.pipe(gulp.dest("dist"));
});
gulp.task("images", function() {
return gulp
.src("src/images/**/*.png")
.pipe(imagemin())
.pipe(gulp.dest("dist/images"));
});
gulp.task("clean:dist", function() {
return del.sync("dist");
});
gulp.task("build", function(callback) {
runSequence("clean:dist", "useref", ["html", "css"], "images", callback);
});
gulp.task("default", ["browserSync", "watch"]);