-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
44 lines (38 loc) · 976 Bytes
/
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
const {
src, dest, parallel, watch,
} = require('gulp');
const uglify = require('gulp-uglify');
const babel = require('gulp-babel');
const rename = require('gulp-rename');
const webserver = require('gulp-webserver');
const env = process.env.NODE_ENV;
const isProduction = env === 'production';
function js() {
return src('src/*.js')
.pipe(babel({
presets: ['@babel/env'],
plugins: ['@babel/plugin-proposal-class-properties'],
}))
.pipe(rename({ suffix: isProduction ? '.min' : '' }))
.pipe(uglify({
output: { beautify: !isProduction },
compress: isProduction,
mangle: isProduction,
}))
.pipe(dest('./'));
}
function server() {
return src('./')
.pipe(webserver({
open: true,
livereload: true,
}));
}
function watchFiles() {
js();
watch('src/*.js', js);
}
if (!isProduction) server();
exports.server = server;
exports.js = js;
exports.default = !isProduction ? watchFiles : parallel(js);