This repository was archived by the owner on Nov 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
124 lines (107 loc) · 2.59 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
123
124
'use strict';
var gulp = require('gulp');
var plumber = require('gulp-plumber');
var del = require('del');
var server = require('browser-sync').create();
var run = require('run-sequence');
var del = require('del');
//Minification
var cssNano = require('gulp-cssnano');
var jsMin = require('gulp-jsmin');
var imagemin = require('gulp-imagemin');
//Rename
var rename = require('gulp-rename');
//PostCSS plugins
var postcss = require('gulp-postcss');
var autoprefixer = require('autoprefixer');
var nested = require('postcss-nested');
var atImport = require('postcss-import');
var mqpacker = require('css-mqpacker');
var customMedia = require('postcss-custom-media');
var cssVariables = require('postcss-css-variables');
//Style
gulp.task('style', function() {
return gulp.src('src/postcss/style.css')
.pipe(plumber())
.pipe(postcss([
atImport(),
nested(),
customMedia(),
cssVariables(),
autoprefixer({browsers: [
'last 2 versions'
]}),
mqpacker({
sort: true
})
]))
.pipe(gulp.dest('build/css'))
.pipe(cssNano())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('build/css'));
});
//JS
gulp.task('js', function() {
return gulp.src('build/js/*.js')
.pipe(jsMin())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('build/js'));
});
//Image
gulp.task('images', function() {
return gulp.src('build/img/*.{png,jpg,gif}')
.pipe(imagemin([
imagemin.optipng({optimizationLevel: 3}),
imagemin.jpegtran({progressive: true})
]))
.pipe(gulp.dest('build/img'));
});
//Clean
gulp.task('clean', function() {
return del('build');
});
//Copy
gulp.task('copy', function() {
return gulp.src([
'src/fonts/**/*.{woff,woff2}',
'src/img/**',
'src/js/**',
'src/*.html'
], {
base: './src'
})
.pipe(gulp.dest('build'));
});
//Server
gulp.task('html:copy', function() {
return gulp.src('src/*.html')
.pipe(gulp.dest('build'));
});
gulp.task('html:update', ['html:copy'], function(done) {
server.reload();
done();
});
gulp.task('js:copy', function() {
return gulp.src('src/js/**/*.js')
.pipe(gulp.dest('build/js'));
});
gulp.task('js:update', ['js:copy'], function(done) {
server.reload();
done();
});
gulp.task('serve', function() {
server.init({
server: 'build/',
notify: false,
open: true,
cors: true,
ui: false
});
gulp.watch('src/postcss/**/*.css', ['style']);
gulp.watch('src/js/**/*.js', ['js:update']);
gulp.watch('src/*.html', ['html:update']);
});
//Run
gulp.task('build', function(done) {
run('clean', 'copy', 'style', 'js', 'images', done)
});