-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
77 lines (66 loc) · 2.06 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
const gulp = require('gulp'),
less = require('gulp-less'),
browserSync = require('browser-sync'),
autoprefixer = require('gulp-autoprefixer'),
ejs = require('gulp-ejs'),
gutil = require('gulp-util'),
rename = require('gulp-rename'),
concat = require('gulp-concat'),
sourcemaps = require('gulp-sourcemaps'),
imagemin = require('gulp-imagemin'),
cleanCSS = require('gulp-clean-css'),
gulpIf = require('gulp-if-else'),
isProduction = process.env.NODE_ENV === 'production';
gulp.task('browserSync', () => {
browserSync.create();
browserSync.init({
server: {
baseDir: 'dist'
},
files: [
'dist/**/*.*'
]
});
});
gulp.task('styles', () => {
gulp.src('src/less/**/*.less')
.pipe(sourcemaps.init())
.pipe(less())
.pipe(concat('all.css'))
.pipe(autoprefixer())
.pipe(gulpIf(isProduction, cleanCSS))
.pipe(sourcemaps.write())
.pipe(gulp.dest('./dist/css'));
});
gulp.task('img', () => {
gulp.src('src/img/**/*.*')
. pipe(gulpIf(isProduction, imagemin))
.pipe(gulp.dest('./dist/img'));
});
gulp.task('svg', () => {
gulp.src('src/img/**/*.svg')
.pipe(gulp.dest('./dist/img'));
});
gulp.task('js', () => {
gulp.src(['src/js/**/*.*', '!src/js/property-selector.js'])
.pipe(sourcemaps.init())
.pipe(concat('all.js'))
.pipe(sourcemaps.write())
.pipe(gulp.dest('./dist/js'));
gulp.src('src/js/property-selector.js')
.pipe(gulp.dest('./dist/js'));
});
gulp.task('html', () => {
gulp.src('src/index.ejs')
.pipe(ejs().on('error', gutil.log))
.pipe(rename('index.html'))
.pipe(gulp.dest('./dist'));
});
gulp.task('watch', () => {
gulp.watch('src/less/**/*.less', ['styles']);
gulp.watch('src/**/*.ejs', ['html']);
gulp.watch('src/img/**/*.*', ['img']);
gulp.watch('src/js/**/*.*', ['js']);
});
gulp.task('default', ['styles', 'html', 'img', 'js', 'watch', 'browserSync']);
gulp.task('prod', ['styles', 'html', 'img', 'js']);