-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
96 lines (83 loc) · 1.91 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
const gulp = require('gulp'),
browser = require('browser-sync').create(),
sass = require('gulp-sass')(require('sass')),
rename = require('gulp-rename'),
cssmin = require('gulp-cssmin'),
imagemin = require('image-min'),
fs = require('fs'),
concat = require('gulp-concat'),
jsmin = require('gulp-jsmin');
let paths = {
input: {
scss: './src/scss/**/*.scss',
js: './src/js/**/*.js',
html: './**/*.html',
images: './src/img/**/*',
fonts: './src/fonts/**/*',
},
output: {
css: './dist/css',
js: './dist/js',
images: './dist/img',
fonts: './dist/fonts',
},
};
function init() {
// clear();
css();
javascript();
images();
fonts();
watcher();
server()
}
function watcher() {
gulp.watch(paths.input.scss, css);
gulp.watch(paths.input.js, javascript);
gulp.watch(paths.input.html).addListener('change', html);
gulp.watch(paths.input.images, images);
}
function css() {
return gulp.src(paths.input.scss)
.pipe(sass().on('error', sass.logError))
.pipe(cssmin())
.pipe(concat('style.min.css'))
.pipe(gulp.dest(paths.output.css))
.pipe(browser.stream());
}
function javascript() {
return gulp.src(paths.input.js)
.pipe(jsmin())
.pipe(rename({
suffix: '.min'
}))
// .pipe(concat('index.min.js'))
.pipe(gulp.dest(paths.output.js))
.pipe(browser.stream());
}
function html() {
return browser.reload();
}
function images() {
return gulp.src(paths.input.images)
.pipe(gulp.dest(paths.output.images))
}
function fonts() {
return gulp.src(paths.input.fonts)
.pipe(gulp.dest(paths.output.fonts))
}
function clear() {
try{
fs.rmSync('./dist',{force: true, recursive: true});
console.log('all files were removed successfully');
}catch(error){
console.log(error);
}
}
function server () {
browser.init({
server: './',
// tunnel: true,
});
}
exports.default = gulp.series(init);