-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.js
89 lines (78 loc) · 2.13 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
const gulp = require('gulp');
const rename = require('gulp-rename');
const eslint = require('gulp-eslint');
const uglify = require('gulp-uglify');
const del = require('del');
const connect = require('gulp-connect');
const gutil = require('gulp-util');
const webpackStream = require("webpack-stream");
const webpackConfig = require ("./webpack.config.js");
// const version = require('./package.json').version;
const jsPath = './src/index.js';
gulp.task('eslint', async () => {
await gulp
.src(jsPath)
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
// Clean
gulp.task('clean', async () => {
await del(['./dist/']);
});
// js:build
gulp.task('js:build', async () => {
await gulp
.src(jsPath)
.pipe(webpackStream(webpackConfig))
.pipe(rename('Vilike.js'))
.pipe(gulp.dest('./dist/'))
.pipe(uglify())
.on('error', function(err) {
gutil.log(gutil.colors.red('[Error]'), err.toString());
})
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('./dist/'));
});
// Server
gulp.task('server', () => {
connect.server({
root: './test/',
livereload: true
});
});
gulp.task('html:dev', async () => {
await gulp.src('./test/index.html').pipe(connect.reload());
});
gulp.task('js:dev', async () => {
await gulp
.src(jsPath)
.pipe(webpackStream(webpackConfig))
.pipe(rename('index.js'))
.pipe(uglify())
.on('error', function(err) {
gutil.log(gutil.colors.red('[Error]'), err.toString());
})
.pipe(gulp.dest('./test/'))
.pipe(connect.reload());
});
gulp.task('js:copy', async () => {
await gulp
.src(jsPath)
.pipe(webpackStream(webpackConfig))
.pipe(rename('index.js'))
.pipe(uglify())
.on('error', function(err) {
gutil.log(gutil.colors.red('[Error]'), err.toString());
})
.pipe(gulp.dest('./test/'))
});
gulp.task('watch', () => {
gulp.watch('./src/index.js', gulp.series('js:dev'));
gulp.watch('./test/index.html', gulp.series('html:dev'));
});
gulp.task(
'default',
gulp.series(gulp.parallel('eslint', 'js:copy', 'server', 'watch'))
);
gulp.task('build', gulp.series('clean', 'eslint', 'js:build'));