-
Notifications
You must be signed in to change notification settings - Fork 4
/
gulpfile.js
112 lines (95 loc) · 2.36 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
/* Modules & variables
-------------------------------------*/
var gulp = require('gulp');
var sass = require('gulp-sass');
var autoprefixer = require('gulp-autoprefixer');
var minifycss = require('gulp-minify-css');
var rename = require('gulp-rename');
var images = require('gulp-imagemin');
const browsersync = require("browser-sync").create();
var uglify = require('gulp-uglify');
/* Paths
-------------------------------------*/
var paths = {
scss: 'stylesheets/main.scss',
css: 'build/css/',
cssReload: 'build/css/main.css',
html: '*.html',
js: 'scripts/main.js',
jsmin: 'build/scripts/'
};
/* Tasks
-------------------------------------*/
//Server
// BrowserSync
function browserSync(done) {
browsersync.init({
server: {
baseDir: "."
},
port: 4000
});
done();
}
// BrowserSync Reload
function browserSyncReload(done) {
browsersync.reload();
done();
}
//Live-reload
var tinylr;
const livereload = () => {
tinylr = require('tiny-lr')();
tinylr.listen(4002);
};
//Styles
const styles = () => {
return gulp.src(paths.scss)
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer())
.pipe(gulp.dest(paths.css))
.pipe(rename({suffix: '.min'}))
.pipe(minifycss())
.pipe(gulp.dest(paths.css));
};
const notifyLiveReload = (event) => {
var fileName = require('path').relative(__dirname, event.path);
returntinylr.changed({
body: {
files: [fileName]
}
});
};
// Image minifyer
const imagesMover = () => {
return gulp.src(['res/images/*.jpg', 'res/images/*.png', 'res/images/**/*'])
.pipe(gulp.dest("build/images"));
};
//JS uglify
const uglifyJob = () => {
return gulp.src(paths.js)
.pipe(uglify())
.pipe(gulp.dest(paths.jsmin))
};
/* Watchers
-------------------------------------*/
// Watch files
const watch = () => {
gulp.watch("stylesheets/**/*.scss", styles);
gulp.watch(paths.js, gulp.series(uglify));
gulp.watch(
[
paths.html,
paths.cssReload
],
gulp.series(browserSyncReload)
);
gulp.watch("./assets/img/**/*", images);
}
const defaultTasks = gulp.parallel( styles, uglifyJob, browserSync,watch);
exports.imagesMover = imagesMover;
exports.styles = styles;
exports.uglifyJob = uglifyJob;
exports.livereload = livereload;
exports.watch=watch;
exports.default = defaultTasks;