-
Notifications
You must be signed in to change notification settings - Fork 9
/
gulpfile.js
126 lines (111 loc) · 3.17 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
var gulp = require("gulp");
var sass = require("gulp-sass");
var browserSync = require("browser-sync").create();
var gulpIf = require("gulp-if");
var uglify = require("gulp-uglify-es").default;
var cssnano = require("gulp-cssnano");
var htmlmin = require("gulp-htmlmin");
var rename = require("gulp-rename");
var imagemin = require("gulp-imagemin");
var del = require("del");
var runSequence = require("run-sequence");
var wait = require("gulp-wait");
var babel = require("gulp-babel");
var autoprefixer = require("gulp-autoprefixer");
var sourcemaps = require("gulp-sourcemaps");
const imageminSvgo = require('imagemin-svgo');
gulp.task("sass", function(cb) {
return (
gulp
.src("assets/styles/sass/**/*.scss")
// .pipe($.sass({
// includePaths: ['node_modules/', '~']
// })
.pipe(wait(700))
// .pipe(sourcemaps.init())
.pipe(sass().on("error", sass.logError))
.pipe(autoprefixer())
// .pipe(sourcemaps.write('./'))
.pipe(gulp.dest("assets/styles/css"))
.pipe(cssnano({ zindex: false }))
.pipe(rename({ suffix: ".min" }))
.pipe(gulp.dest("assets/styles/css"))
.pipe(gulp.dest("dist/assets/styles/css"))
);
});
function browserSyncInit(done) {
browserSync.init({
server: {
// baseDir: '/'
},
startPath: "index.html"
});
done();
}
function browserSyncReload(done) {
browserSync.reload();
done();
}
gulp.task("compilejs", function() {
return gulp
.src("assets/js/main/*.js")
.pipe(wait(400))
.pipe(babel({ presets: ["es2015", "stage-3"] }))
.pipe(gulp.dest("assets/js/es5"))
.pipe(gulpIf("*.js", uglify()))
.pipe(rename({ suffix: ".min" }))
.pipe(gulp.dest("assets/js/es5"))
.pipe(gulp.dest("dist/assets/js/es5"));
});
gulp.task("minifyjs", function() {
return gulp
.src("assets/js/es5/**/*")
.pipe(gulpIf("*.js", uglify()))
.pipe(gulp.dest("dist/assets/js"));
});
gulp.task("minifycss", function() {
return gulp
.src("assets/styles/css/**/*")
.pipe(gulpIf("*.css", cssnano({ zindex: false })))
.pipe(gulp.dest("dist/assets/styles/css"));
});
gulp.task("vendorcss", function() {
return gulp
.src("assets/styles/vendor/**/*.css")
.pipe(gulp.dest("dist/assets/styles/vendor"));
});
gulp.task("minifyhtml", function() {
return gulp
.src("*.html")
.pipe(htmlmin())
.pipe(gulp.dest("dist"));
});
gulp.task("images", function() {
return gulp
.src("assets/images/**/*.+(png|jpg|gif|svg)")
.pipe(imagemin())
.pipe(gulp.dest("dist/assets/images"));
});
gulp.task("font", function() {
return gulp.src("assets/fonts/**/*").pipe(gulp.dest("dist/assets/fonts"));
});
gulp.task("clean:dist", function(done) {
del.sync("dist");
done();
});
function watchFiles() {
gulp.watch("assets/styles/sass/**/*.scss", gulp.series("sass", browserSyncReload));
gulp.watch("assets/js/main/*.js", gulp.series("compilejs", browserSyncReload));
gulp.watch("*.html", gulp.series(browserSyncReload));
}
gulp.task("default", gulp.series("sass", "compilejs", browserSyncInit, watchFiles));
gulp.task("build", gulp.series(
"clean:dist",
"sass",
"compilejs",
"minifyjs",
"minifycss",
"minifyhtml",
"images",
"font"
));