forked from zalog/placeholder-loading
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
118 lines (97 loc) · 2.65 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
'use strict';
const gulp = require('gulp'),
csscompile = require('gulp-sass'),
postcss = require('gulp-postcss'),
autoprefixer = require('autoprefixer'),
cssnano = require('cssnano'),
header = require('gulp-header'),
rename = require('gulp-rename'),
del = require('del'),
browsersync = require('browser-sync').create(),
gulputil = require('gulp-util'),
packageJson = require('./package.json'),
src = './src',
dist = './dist';
var contributors = (function() {
if ( typeof packageJson.contributors == "undefined" ) return false;
let output = '';
for (let i = 0; i < packageJson.contributors.length; i++) {
if ( i > 0 ) output += ", ";
output += packageJson.contributors[i];
}
return " * Contributors: " + output;
})(),
banner = [
"/**",
" * " + packageJson.name + " v" + packageJson.version,
" * Author: " + packageJson.author,
" * License: " + packageJson.license
];
if ( contributors ) banner.push(contributors);
banner.push(" **/", "");
banner = banner.join("\n");
var copyChanged = function(obj) {
if ( obj.type === 'changed') {
return gulp.src(obj.path, {base: src})
.pipe(gulp.dest(dist))
.on('end', () => gulputil.log('Finished', "'" + gulputil.colors.cyan('copyChanged') + "'", obj.path) );
}
};
function clean() {
return del(
[
dist + '/**/*',
'!' + dist + '/.git/'
],
{force: true}
);
}
function html() {
return gulp.src(src + '/*.html')
.pipe(gulp.dest(dist));
}
function cssCompile() {
return gulp.src(src + '/scss/placeholder-loading.scss')
.pipe(csscompile())
.pipe(gulp.dest(dist + '/css/'))
.pipe(browsersync.stream());
}
function cssOptimize() {
return gulp.src(dist + '/css/placeholder-loading.css')
.pipe(postcss([
autoprefixer()
]))
.pipe(header(banner))
.pipe(gulp.dest(dist + '/css/'))
// min
.pipe(postcss([
autoprefixer(),
cssnano()
]))
.pipe(header(banner))
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest(dist + '/css/'));
}
const css = gulp.series(cssCompile, cssOptimize);
function serve() {
browsersync.init({
server: dist,
notify: false,
reloadDelay: 500,
ghostMode: false
});
}
function watch() {
gulp.watch(src + '/*.html', copyChanged);
gulp.watch(src + '/scss/**/*', cssCompile);
gulp.watch(dist + "/*.html").on('change', browsersync.reload);
}
// grouped tasks by use case
const dev = gulp.parallel(html, cssCompile);
const build = gulp.series(clean, html, css);
exports.build = build;
exports.serve = serve;
exports.default = gulp.parallel(
gulp.series(dev, serve),
watch
);