-
-
Notifications
You must be signed in to change notification settings - Fork 149
/
Copy pathgulpfile.js
114 lines (91 loc) · 2.69 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
'use strict';
const gulp = require('gulp');
const csscompile = require('gulp-sass')(require('sass'));
const postcss = require('gulp-postcss');
const autoprefixer = require('autoprefixer');
const cssnano = require('cssnano');
const header = require('gulp-header');
const rename = require('gulp-rename');
const del = require('del');
const browsersync = require('browser-sync').create();
const packageJson = require('./package.json');
const src = './src';
const dist = './dist';
const contributors = (() => {
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;
})();
let banner = [
"/**",
" * " + packageJson.name + " v" + packageJson.version,
" * Author: " + packageJson.author,
" * License: " + packageJson.license
];
if ( contributors ) banner.push(contributors);
banner.push(" **/", "");
banner = banner.join("\n");
const copyFile = (file) => {
if (!file) return;
return gulp.src(file, {base: src})
.pipe(gulp.dest(dist))
.on('end', () => console.log(`[${new Date().toTimeString().split(' ')[0]}] Finished 'copyFile' ${file}`) );
};
const isProduction = (process.env.NODE_ENV === 'production') ? true : false;
const clean = () => del(
[
dist + '/**/*',
'!' + dist + '/.git/'
],
{force: true}
);
const html = () => gulp.src(src + '/*.html')
.pipe(gulp.dest(dist));
function css() {
const stream = gulp.src(src + '/scss/placeholder-loading.scss')
.pipe(csscompile())
.pipe(postcss([
autoprefixer()
]))
.pipe(header(banner))
.pipe(gulp.dest(dist + '/css/'));
if (isProduction) {
stream
.pipe(postcss([
autoprefixer(),
cssnano()
]))
.pipe(header(banner))
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest(dist + '/css/'));
}
stream.pipe(browsersync.stream());
return stream;
}
const serve = () => browsersync.init({
server: dist,
notify: false,
reloadDelay: 500,
ghostMode: false,
open: false
});
const watch = () => {
gulp.watch(src + '/*.html')
.on('change', copyFile);
gulp.watch(src + '/scss/**/*')
.on('change', gulp.series(css));
gulp.watch(dist + "/*.html")
.on('change', browsersync.reload);
}
// grouped tasks by use case
const build = gulp.series(clean, html, css);
exports.build = build;
exports.serve = serve;
exports.default = gulp.parallel(
gulp.series(build, serve),
watch
);