-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
122 lines (109 loc) · 2.74 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
var gulp = require('gulp'),
sass = require('gulp-sass');
gutil = require('gulp-util'),
clean = require('gulp-clean'),
uglify = require('gulp-uglify'),
rename = require('gulp-rename'),
concat = require('gulp-concat'),
postCss = require('gulp-postcss'),
imagemin = require('gulp-imagemin'),
cleanCss = require('gulp-clean-css'),
sourcemaps = require('gulp-sourcemaps'),
browserSync = require('browser-sync').create();
// PATHS OBJECT
var paths = {
scss: {
all: 'src/scss/**/*.scss',
main: 'src/scss/main.scss'
},
html: 'static/**/*.html',
images: 'src/images/**/*',
fonts: 'src/fonts/*',
js: 'static/js/*.js'
}
// CSS LINTING
gulp.task('lint-css', function lintCssTask() {
const gulpStylelint = require('gulp-stylelint');
return gulp
.src(paths.scss.all)
.pipe(gulpStylelint({
reporters: [
{formatter: 'string', console: true}
]
}));
});
// CSS TASK
gulp.task('styles', ['lint-css'], function() {
var processors = [
require('autoprefixer')
];
return gulp.src(paths.scss.main)
.pipe(sass().on('error', function(err) {
gutil.log(err);
this.emit('end');
}))
.pipe(sourcemaps.init())
.pipe(postCss(processors))
.pipe(gulp.dest('static/dist/css'))
.pipe(cleanCss())
.pipe(rename({
suffix: '.min'
}))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('static/dist/css'))
.pipe(browserSync.stream());
});
// HTML TASK
gulp.task('html', function() {
return gulp.src(paths.html)
.pipe(browserSync.stream());
});
// JS TASK
gulp.task('js', function() {
return gulp.src(paths.js)
.pipe(concat('main.js'))
.pipe(gulp.dest('dist/js'))
.pipe(uglify())
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest('dist/js'))
.pipe(browserSync.stream());
});
// FONTS TASK
gulp.task('fonts', function() {
return gulp.src(paths.fonts)
.pipe(gulp.dest('dist/fonts'))
.pipe(browserSync.stream());
});
// IMAGES TASK
gulp.task('images', function() {
return gulp.src(paths.images)
.pipe(imagemin())
.pipe(gulp.dest('dist/images'))
.pipe(browserSync.stream());
});
// WATCH TASK
gulp.task('watch', function() {
gulp.watch(paths.scss.all, ['styles']);
gulp.watch(paths.html, ['html']);
gulp.watch(paths.js, ['js']);
gulp.watch(paths.fonts, ['fonts']);
gulp.watch(paths.images, ['images', 'clean']);
});
// BROWSER SYNC TASK
gulp.task('browser-sync', function() {
browserSync.init({
server: {
baseDir: "./static"
},
port: 8080
});
});
// CLEAN TASK
gulp.task('clean', function () {
return gulp.src('static/dist', {read: false})
.pipe(clean());
});
// DEFAULT TASK
gulp.task('default',['styles', 'html', 'js', 'images', 'fonts', 'browser-sync', 'watch']);