-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
149 lines (136 loc) · 3.65 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
"use strict";
import gulp from "gulp"; // gulping!
import browserSync from "browser-sync"; // sync browser with code changes!
import lint from "gulp-eslint"; // lint JS files!
import imagemin, { mozjpeg, optipng } from "gulp-imagemin"; // optimizing images!
import rename from "gulp-rename"; // renaming JS!
import uncss from "gulp-uncss"; // shedding CSS!
import crass from "gulp-crass"; // optimizing CSS!
import concat from "gulp-concat"; // concat helper!
import historyApiFallback from "connect-history-api-fallback"; // local development helper!
// configuration object
var config = {
proxyUrl: "http://localhost:8080",
browser: "chrome",
port: 7001,
paths: {
files: "**/*.*",
images: "images/**/*.*",
applicationJavascript: [
"scripts/app.js",
"scripts/controllers/*.js",
"scripts/directives/responsiveImage.js",
],
libJavascript: [
"node_modules/angular/angular.min.js",
"node_modules/@uirouter/angularjs/release/angular-ui-router.min.js",
"node_modules/materialize-css/dist/js/materialize.min.js",
],
styles: "styles/*.css",
},
};
// destination configuration object
var destConfig = {
paths: {
images: "dist/images",
javascript: "dist/scripts",
styles: "dist/styles",
stylesUncss: "dist/stylesUncss",
libJavascript: "dist/scripts/lib",
},
};
// browser-sync task
gulp.task("browser-sync", function () {
browserSync.init({
files: [config.paths.files],
browser: config.browser,
port: config.port,
server: {
baseDir: "./",
middleware: [historyApiFallback()],
},
});
});
// Library scripts task
gulp.task("lib-scripts", function () {
return gulp
.src(config.paths.libJavascript)
.pipe(concat("lib-bundle.js"))
.pipe(
rename({
suffix: ".min",
})
)
.pipe(gulp.dest(destConfig.paths.libJavascript));
});
// image task
gulp.task("images", function () {
return gulp
.src(config.paths.images, { encoding: false })
.pipe(
imagemin([
mozjpeg({
quality: 75,
progressive: true,
}),
optipng({ optimizationLevel: 5 }),
])
)
.pipe(gulp.dest(destConfig.paths.images));
});
// Scripts task
gulp.task("scripts", gulp.series("lib-scripts"), function () {
return gulp
.src(config.paths.applicationJavascript)
.pipe(concat("bundle.js"))
.pipe(
rename({
suffix: ".min",
})
)
.pipe(gulp.dest(destConfig.paths.javascript));
});
// linting task
gulp.task("lint", function () {
return gulp
.src(config.paths.applicationJavascript)
.pipe(
lint({
config: "eslint.config.json",
})
)
.pipe(lint.format());
});
//uncss-ing task
gulp.task("uncss", function () {
return gulp
.src(config.paths.styles)
.pipe(
uncss({
html: ["index.html", "templates/**/*.html"],
})
)
.pipe(gulp.dest(destConfig.paths.stylesUncss));
});
// crass, used for CSS minification
gulp.task("crass", function () {
return gulp
.src(config.paths.styles)
.pipe(
crass({
pretty: false,
})
)
.pipe(gulp.dest(destConfig.paths.styles));
});
// watch task for any html/js changes
gulp.task("watch", function () {
gulp.watch(config.paths.applicationJavascript, gulp.series("lint"));
gulp.watch(config.paths.applicationJavascript, gulp.series("scripts"));
gulp.watch(config.paths.libJavascript, gulp.series("lib-scripts"));
gulp.watch(config.paths.images, gulp.series("images"));
gulp.watch(config.paths.styles, gulp.series("crass"));
});
// default gulp tasks
var defaultTasks = gulp.parallel("browser-sync", "watch");
gulp.task("default", defaultTasks, function () {});