-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
120 lines (101 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
// STEP - 1
// Initializing And Acquiring all Required packages
const gulp = require("gulp");
const less = require("gulp-less");
const autoPrefixLess = require("less-plugin-autoprefix");
const lessGlob = require("less-plugin-glob");
const cssMin = require("gulp-clean-css");
const jsMin = require("gulp-uglify-es").default;
const concat = require("gulp-concat");
const htmlMin = require("gulp-htmlmin");
const sourceMap = require("gulp-sourcemaps");
const imageMin = require("gulp-imagemin");
const rename = require("gulp-rename");
const browserSync = require("browser-sync").create();
const ghpages = require("gulp-gh-pages");
var lessPrefix = new autoPrefixLess({
browsers: ["last 2 versions"]
});
// STEP - 2
// Creating Individual Tasks
//HTML minify Task
gulp.task("Html-Minify", function () {
gulp.src("src/*.html")
.pipe(htmlMin({
collapseWhitespace: true
}))
.pipe(gulp.dest("dist/"))
.pipe(browserSync.stream());
});
// JavaScript Minify task
gulp.task("Js-Minify", function () {
gulp.src(['src/assets/js/jquery.zoom.min.js', 'src/assets/js/lightslider.min.js'])
.pipe(concat('imagepreviewer.min.js'))
.pipe(sourceMap.init())
.pipe(jsMin())
.pipe(sourceMap.write("/maps"))
.pipe(gulp.dest("dist/assets/js"))
.pipe(browserSync.stream());
});
// CSS Minify task
gulp.task("Css-Minify", function () {
gulp.src("src/assets/css/*.css")
.pipe(concat('imagepreviewer.min.css'))
.pipe(sourceMap.init())
.pipe(cssMin({
level: {
1: {
specialComments: 0
}
}
}))
.pipe(sourceMap.write("/maps"))
.pipe(gulp.dest("dist/assets/css/"))
.pipe(browserSync.stream());
});
// Image Minify Task
gulp.task("Image-Minify", function () {
gulp.src("src/assets/images/*")
.pipe(imageMin({
verbose: true
}))
.pipe(gulp.dest("dist/assets/images/"))
});
// Less Compiler LESS->CSS and CSS minify task
gulp.task("less", function () {
gulp.src("src/assets/less/**.*less")
.pipe(rename("styles.min.css"))
.pipe(sourceMap.init())
.pipe(less({
plugins: [lessPrefix, lessGlob]
}))
.pipe(cssMin())
.pipe(sourceMap.write("/maps"))
.pipe(gulp.dest("dist/assets/css/"))
.pipe(browserSync.stream());
});
// Deploy on Github-Pages Task
gulp.task("deploy", function () {
return gulp.src("./dist/**/*")
.pipe(ghpages({
message: "Update by Gulp-Task"
}));
});
// STEP - 3
// Watch and Serve Task
gulp.task("serve", function () {
browserSync.init({
server: "dist",
port: 2712,
host: "192.168.10.66",
browser: "Firefox"
});
gulp.watch("src/assets/less/**/*.less", ["less"]);
gulp.watch("src/*.html", ["Html-Minify"]);
gulp.watch("src/assets/js/*.js", ["Js-Minify"]);
gulp.watch("src/assets/images/*", ["Image-Minify"]);
gulp.watch("dist/assets/*.html").on("change", browserSync.reload);
});
// STEP - 4
// Gulp Default Task
gulp.task("default", ["Image-Minify", "Html-Minify", "Js-Minify", "less", "serve"]);