-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
112 lines (98 loc) · 2.09 KB
/
Copy pathgulpfile.js
File metadata and controls
112 lines (98 loc) · 2.09 KB
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
const { src, dest, watch, series } = require('gulp');
const { delDir } = require('./until/file');
const uglifycss = require('gulp-uglifycss');
const htmlmin = require('gulp-htmlmin');
const babel = require('gulp-babel');
const uglify = require('gulp-uglify');
const fileinclude = require('gulp-file-include');
const browserSync = require('browser-sync').create();
/**
* html task
*/
async function htmlTask() {
return src('src/**.html')
.pipe(fileinclude({
prefix: '@@',
basepath: '@file'
}))
.pipe(htmlmin({ collapseWhitespace: true }))
.pipe(dest('dist'));
}
/**
* js task
*/
async function jsTask(env) {
delDir('dist/js/');
if (env === 'build') {
return src('src/js/*.js')
.pipe(babel({
presets: ['@babel/env']
}))
.pipe(uglify())
.pipe(dest('dist/js/'))
} else {
return src('src/js/**')
.pipe(dest('dist/js/'));
}
}
/**
* css task
*/
async function cssTask() {
delDir('dist/css/');
return src('src/css/**')
.pipe(uglifycss({
"maxLineLen": 80,
"uglyComments": true
})).pipe(dest('dist/css/'))
}
/**
* img task
*/
async function imgTask() {
delDir('dist/img/');
return src('src/img/**')
.pipe(dest('dist/img/'));
}
/**
* plugin task
*/
async function pluginTask() {
delDir('dist/plugin/');
return src('src/plugin/**')
.pipe(dest('dist/plugin/'));
}
/**
* all task
*/
async function tasks(env) {
await htmlTask();
await jsTask(env);
await pluginTask();
await cssTask();
}
/**
* start
*/
async function start() {
await tasks();
watch('src/css/**', cssTask);
watch('src/js/**', jsTask);
watch('src/plugin/**', pluginTask);
watch('src/**.html', htmlTask);
watch('src/public/**.html', series(htmlTask));
browserSync.init({
port: 8000,
server: {
baseDir: "./dist",
}
});
}
/**
* build
*/
async function build() {
await tasks('build');
}
exports.start = start;
exports.build = build;