-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
94 lines (79 loc) · 2.33 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
const
gulp = require('gulp'),
babel = require('gulp-babel'),
newer = require('gulp-newer'),
imagemin = require('gulp-imagemin'),
htmlclean = require('gulp-htmlclean'),
uglify = require('gulp-uglify'),
sass = require('gulp-sass'),
rename = require('gulp-rename'),
postcss = require('gulp-postcss'),
assets = require('postcss-assets'),
autoprefixer = require('autoprefixer'),
mqpacker = require('css-mqpacker'),
cssnano = require('cssnano')
const devBuild = (process.env.NODE_ENV !== 'production')
const folder = {
src: 'src/',
build: 'build/'
}
gulp.task('images', () => {
const out = folder.build + 'img/'
return gulp
.src(folder.src + 'img/**/*')
.pipe(newer(out))
.pipe(imagemin({optimizationLevel: 5}))
.pipe(gulp.dest(out))
})
gulp.task('html', gulp.parallel('images', () => {
const out = folder.build + 'html/'
let page = gulp
.src(folder.src + 'html/**/*')
.pipe(newer(out))
if (!devBuild) {
page = page.pipe(htmlclean())
}
return page.pipe(gulp.dest(out))
}))
gulp.task('js', () => {
let jsbuild = gulp
.src(folder.src + 'js/**/*')
.pipe(babel())
if (!devBuild) {
jsbuild = jsbuild
.pipe(uglify())
}
return jsbuild.pipe(gulp.dest(folder.build + 'js/'))
})
gulp.task('css', gulp.parallel('images', () => {
var postCssOpts = [
assets({loadPaths: ['images/']}),
autoprefixer({
browsers: ['last 2 versions', '> 2%']
}),
mqpacker
];
if (!devBuild) {
postCssOpts.push(cssnano);
}
return gulp
.src(folder.src + 'scss/main.scss')
.pipe(sass({outputStyle: 'nested', imagePath: 'images/', precision: 3, errLogToConsole: true}))
.pipe(postcss(postCssOpts))
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest(folder.build + 'css/'))
}))
gulp.task('fonts', () => {
return gulp
.src(folder.src + 'fonts/**/*')
.pipe(gulp.dest(folder.build + 'fonts/'))
})
gulp.task('build', gulp.parallel('html', 'css', 'js', 'fonts'))
gulp.task('watch', function () {
gulp.watch(folder.src + 'img/**/*', gulp.parallel('images'))
gulp.watch(folder.src + 'html/**/*', gulp.parallel('html'))
gulp.watch(folder.src + 'js/**/*', gulp.parallel('js'))
gulp.watch(folder.src + 'scss/**/*', gulp.parallel('css'))
gulp.watch(folder.src + 'fonts/*', gulp.parallel('fonts'))
});
gulp.task('default', gulp.parallel('build', 'watch'))