-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathgulpfile.js
125 lines (111 loc) · 3.11 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
var gulp = require("gulp");
var plugins = require("gulp-load-plugins")();
var browserSync = require("browser-sync").create();
//const autoprefixer = require('gulp-autoprefixer');
// Config Object.
var config = {
assetsDir: "./src",
sassPattern: "scss/*.scss",
production: !!plugins.util.env.production,
sourceMaps: !plugins.util.env.production
};
var app = {};
app.addStyle = function(paths, outputFilename) {
gulp
.src(paths)
.pipe(plugins.plumber())
.pipe(plugins.if(config.sourceMaps, plugins.sourcemaps.init()))
.pipe(plugins.sass())
.pipe(plugins.concat(outputFilename))
.pipe(plugins.cleanCss())
.pipe(plugins.if(config.sourceMaps, plugins.sourcemaps.write(".")))
.pipe(gulp.dest("dist/css"));
};
app.addScript = function(paths, outputFilename) {
gulp
.src(paths)
.pipe(plugins.plumber())
.pipe(plugins.if(config.sourceMaps, plugins.sourcemaps.init()))
.pipe(plugins.concat(outputFilename))
.pipe(plugins.uglify())
.pipe(plugins.if(config.sourceMaps, plugins.sourcemaps.write(".")))
.pipe(gulp.dest("dist/js"));
};
// Copy method.
app.copy = function(srcFiles, outputDir) {
gulp.src(srcFiles).pipe(gulp.dest(outputDir));
};
// Sass styles task. Not used yet.
gulp.task("styles", function() {
return app.addStyle(
[
"./node_modules/bootstrap/dist/css/bootstrap.min.css",
config.assetsDir + "/scss/**/*.scss",
"./node_modules/font-awesome/css/font-awesome.min.css"
],
"style.min.css"
);
});
// Scripts task.
gulp.task("scripts", function() {
return app.addScript(
[
"./node_modules/js-polyfills/polyfill.min.js",
"./node_modules/jquery/dist/jquery.min.js",
"./node_modules/bootstrap/dist/js/bootstrap.min.js",
"./node_modules/wowjs/dist/wow.min.js",
"./node_modules/jquery-visible/jquery.visible.min.js",
"./node_modules/fittext.js/jquery.fittext.js",
"./src/js/jsquery.easing.min.js",
config.assetsDir + "/js/**/*.js"
],
"scripts.min.js"
);
});
// Task for fonts
gulp.task("html", function() {
return app.copy("./src/*.html", ".");
});
// Task for fonts
gulp.task("fonts", function() {
return app.copy("./node_modules/font-awesome/fonts/**", "dist/fonts");
});
// Images optimization.
gulp.task("images", function() {
gulp
.src(config.assetsDir + "/img/**")
.pipe(plugins.imagemin())
.pipe(gulp.dest("dist/img"));
});
gulp.task("favicons", function() {
gulp.src(config.assetsDir + "/favicons/**").pipe(gulp.dest("dist/favicons"));
});
// Static server
gulp.task("browser-sync", function() {
!config.production
? browserSync.init({
server: {
baseDir: "./"
}
})
: plugins.util.noop();
});
// Watch task. Watches for changes.
gulp.task("watch", function() {
if (!config.production) {
gulp.watch(config.assetsDir + "/" + config.sassPattern, ["styles"]);
gulp.watch(config.assetsDir + "/js/**/*.js", ["scripts"]);
gulp.watch("*.html").on("change", browserSync.reload);
}
});
// Defautl task.
gulp.task("default", [
"html",
"styles",
"scripts",
"images",
"favicons",
"fonts",
"browser-sync",
"watch"
]);