-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
141 lines (131 loc) · 3.88 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/************************* gulp 4.x ********************************
https://nodejs.org/ko/download/
npm install gulp-cli -g
npm install gulp -g
npm install gulp --save-dev
npm install gulp-concat --save-dev
npm install gulp-uglify --save-dev
npm install gulp-sourcemaps --save-dev
npm install node-sass gulp-sass --save-dev
npm install gulp-autoprefixer --save-dev
npm install gulp-file-include --save-dev
npm install gulp-pretty-html --save-dev
npm install browser-sync --save-dev
npm install gulp del --save-dev
npm install gulp-wait --save-dev
**************************************************************/
var gulp = require('gulp')
, concat = require('gulp-concat')
, fileinclude = require('gulp-file-include')
, prettyHtml = require('gulp-pretty-html')
, sass = require('gulp-sass')
, sourcemaps = require('gulp-sourcemaps')
, autoprefixer = require('gulp-autoprefixer')
, minJs = require('gulp-uglify')
, server = require('browser-sync').create()
, clean = require('del')
, wait = require('gulp-wait');
var paths = {
srcHtml : ['./src/html/**/*.*', '!./src/html/include/**/*.*'],
srcInclude : './src/html/include',
srcScss : ['./src/scss/style.scss', './src/scss/semantic.min.css', './src/scss/calendar.min.css', './src/scss/swiper.min.css'],
srcJs : ['./src/js/**/*.*'],
srcMinJs : ['./src/js/jquery-1.12.4.js', './src/js/ui.js'],
srcImg : ['./src/img/**/*.*'],
srcFont : ['./src/font/**/*.*'],
srcIncluder : './src/html/include',
distHtml : './dist/html/',
distCss : './dist/css/',
distJs : './dist/js/',
distImg : './dist/img/',
distFont : './dist/font/',
// min
minScss : 'style.min.css',
minJs : 'script.min.js',
// watch
watchIndex : './index.html',
watchHtml : './src/html/**/*.*',
watchJs : './src/js/**/*.*',
watchScss : './src/scss/**/*.*',
watchImg : './src/img/**/*.*',
// clean
cleanAll : ['./dist/**/*.*', '!./dist/video/**/*.*', '!./dist/font/**/*.*']
}
function cleanFile(done){
console.log('clean file');
clean(paths.cleanAll);
done();
}
function htmlBuild(done){
gulp.src(paths.srcHtml)
.pipe(fileinclude({
prefix: '@@',
basepath: paths.srcIncluder
}))
.pipe(prettyHtml())
.pipe(gulp.dest(paths.distHtml));
done();
}
function scssBuild(done){
gulp.src(paths.srcScss, {allowEmpty:true})
.pipe(wait(200))
.pipe(sourcemaps.init())
.pipe(sass({ outputStyle: "compact" }))
// .pipe(autoprefixer())
.pipe(sourcemaps.write('../maps'))
.pipe(gulp.dest(paths.distCss));
done();
}
function autoprefixerPatch(done){
gulp.src('./dist/css/style.css', {allowEmpty:true})
.pipe(wait(200))
.pipe(autoprefixer({
cascade: false
}))
.pipe(concat('./style.min.css'))
.pipe(gulp.dest(paths.distCss));
done();
}
function jsBuild(done){
gulp.src(paths.srcMinJs)
.pipe(gulp.dest(paths.distJs))
.pipe(minJs())
.pipe(concat(paths.minJs))
.pipe(gulp.dest(paths.distJs));
gulp.src(paths.srcJs)
.pipe(gulp.dest(paths.distJs));
done();
}
function imageBuild(done){
gulp.src(paths.srcImg)
.pipe(gulp.dest(paths.distImg));
done();
}
function fontBuild(done){
gulp.src(paths.srcFont)
.pipe(gulp.dest(paths.distFont))
done();
}
function watchFile(done){
gulp.watch(paths.watchIndex, gulp.series(reload));
gulp.watch(paths.watchHtml, gulp.series(htmlBuild, gulp.parallel(reload)));
gulp.watch(paths.watchScss, gulp.series(scssBuild, gulp.parallel(reload)));
gulp.watch(paths.watchJs, gulp.series(jsBuild, gulp.parallel(reload)));
gulp.watch(paths.watchImg, gulp.series(imageBuild, gulp.parallel(reload)));
done();
}
function reload(done){
setTimeout(function(){
server.reload();
},500);
done();
}
function serve(done){
server.init({
server: {
baseDir: './'
}
});
done();
}
gulp.task('default', gulp.series(cleanFile, gulp.parallel(htmlBuild, imageBuild, jsBuild, scssBuild, fontBuild), autoprefixerPatch, serve, watchFile));