-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgulpfile.js
221 lines (189 loc) · 4.63 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/* -------------------------------------------------------------------------
* IDENTITY LANDING PAGE | @version 1.0.2 | @author Vantage Design | @license https://github.com/vantagedesign/identity-landing-page/blob/master/LICENSE.md
* Gulpfile.
* ------------------------------------------------------------------------ */
/* Define requirements */
/* Core */
var gulp = require('gulp');
var plumber = require('gulp-plumber');
var notify = require('gulp-notify');
var rename = require('gulp-rename');
var browsersync = require('browser-sync');
/* css */
var cleancss = require('gulp-clean-css');
var autoprefixer = require('gulp-autoprefixer');
var scss = require('gulp-sass');
/* js */
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
/* files */
var del = require('del');
/* Define source and destination paths for file types */
var dist = 'dist/';
var paths = {
html: {
src: 'src/**/*.html',
dest: dist
},
scss: {
src: 'src/css/**/*.scss',
dest: dist + 'css/'
},
css: {
src: 'src/css/**/*.css',
dest: dist + 'css/'
},
js: {
src: 'src/js/**/*.js',
dest: dist + 'js/'
},
plugins: {
js: {
src: [
'src/plugins/**/*.js'
],
dest: dist + 'js/'
}
},
copy: {
src: [
'src/**/*.*',
'!src/{css,js}/**/*.*',
'!src/**/*.{psd}'
],
dest: dist
},
}
var autoprefix_setting = [
'last 2 version',
'> 1%',
'ie 8',
'ie 9',
'ios 6',
'android 4'
]
/** --------------------------------------------
* CSS processing
--------------------------------------------- */
/* Process CSS */
function css_process(){
return gulp.src(paths.css.src)
.pipe(plumber())
.pipe(autoprefixer(autoprefix_setting))
.pipe(gulp.dest(paths.css.dest))
.pipe(cleancss({keepBreaks: false}))
.pipe(rename({ extname: '.min.css' }))
.pipe(gulp.dest(paths.css.dest))
.pipe(notify({message: 'CSS processed'})
);
}
/* Process SCSS */
function scss_process(){
return gulp.src(paths.scss.src)
.pipe(plumber())
.pipe(scss().on('error', scss.logError))
.pipe(autoprefixer(autoprefix_setting))
.pipe(gulp.dest(paths.css.dest))
.pipe(cleancss({keepBreaks: false}))
.pipe(rename({ extname: '.min.css' }))
.pipe(gulp.dest(paths.scss.dest))
.pipe(notify({message: 'SCSS processed'})
);
}
/** --------------------------------------------
* Javascript processing
--------------------------------------------- */
/* Process ES5 Javascript */
function js_process(){
return gulp.src(paths.js.src)
.pipe(plumber())
.pipe(concat('main.js'))
.pipe(gulp.dest(paths.js.dest))
.pipe(uglify())
.pipe(rename({ extname: '.min.js' }))
.pipe(gulp.dest(paths.js.dest))
.pipe(notify({message: 'Javascript processed'})
);
}
/* Process ES5 Javascript */
function js_plugins_process(){
return gulp.src(paths.plugins.js.src)
.pipe(plumber())
.pipe(concat('plugins.js'))
.pipe(gulp.dest(paths.plugins.js.dest))
.pipe(rename({ extname: '.min.js' }))
.pipe(uglify())
.pipe(gulp.dest(paths.plugins.js.dest))
.pipe(notify({message: 'Javascript plugins processed'})
);
}
/*---------------------------------------------
* Copy other files
*---------------------------------------------*/
/* Copy other src files to their dest */
function html_process() {
return gulp.src(paths.html.src, {base: 'src/'})
.pipe(gulp.dest(paths.html.dest))
}
function copy_files() {
return gulp.src(paths.copy.src, {base: 'src/'})
.pipe(gulp.dest(paths.copy.dest))
}
/** --------------------------------------------
* Launch browsersync server
--------------------------------------------- */
gulp.task('browsersync', function(cb){
browsersync.init(['**/*.css', '**/*.js', '**/*.html', '**/*.php,'], {
server: {
baseDir: dist
}
}, cb);
console.log('Browsersync server started');
});
/*---------------------------------------------
* Cleanup
*---------------------------------------------*/
/* Clean all dest files */
function clean_dist() {
return del(dist);
}
/*---------------------------------------------
* Gulp functions & tasks
*---------------------------------------------*/
/* Define files to watch */
function watch(cb) {
gulp.watch(paths.html.src, html_process);
gulp.watch(paths.css.src, css_process);
gulp.watch(paths.scss.src, scss_process);
gulp.watch(paths.js.src, js_process);
gulp.watch(paths.plugins.js.src, js_plugins_process);
gulp.watch(paths.copy.src, copy_files);
cb();
}
/* Internal tasks */
var init = gulp.series(
clean_dist,
css_process,
scss_process,
js_process,
js_plugins_process,
html_process,
copy_files
);
/* Exposed tasks */
gulp.task('dev',
gulp.series(
init,
gulp.parallel(
watch,
'browsersync'
)
)
);
/* Exposed tasks */
gulp.task('build',
gulp.series(
init
)
);
gulp.task('clean', clean_dist);