-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgulpfile.js
94 lines (87 loc) · 2.41 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
const gulp = require('gulp');
const concat = require('gulp-concat');
const uglifyJS = require('gulp-uglify');
const babel = require('gulp-babel');
const fs = require('fs');
gulp.task('test', () => {
console.log('yes');
});
gulp.task('expressjs', () => {
gulp
.src('./koa.js')
.pipe(babel({ presets: ['@babel/preset-env'] }))
.pipe(uglifyJS())
.pipe(concat('buddle.js'))
.pipe(gulp.dest('./dist'));
});
const ROOT = './buddle-server';
function distDirs(dir) {
const files = fs.readdirSync(__dirname + dir);
files.forEach((item) => {
const controller = require(__dirname + dir + '/' + item);
if (controller) {
gulp
.src(`.${dir}/${item}`)
.pipe(
babel({
// presets: ['@babel/preset-env'],
plugins: ['@babel/plugin-transform-runtime'],
}),
)
.pipe(uglifyJS())
.pipe(concat(`${item}`))
.pipe(gulp.dest(`${ROOT}/${dir}`));
}
});
}
gulp.task('expresscon', () => {
// const files = fs.readdirSync(__dirname + '/controllers');
// files.forEach((item) => {
// const controller = require(__dirname + '/controllers/' + item);
// if (controller) {
// gulp
// .src(`./controllers/${item}`)
// .pipe(babel({ presets: ['@babel/preset-env'] }))
// .pipe(uglifyJS())
// .pipe(concat(`${item}`))
// .pipe(gulp.dest('./controllers/dist/'));
// }
// });
distDirs('/controllers');
distDirs('/common');
distDirs('/dbmodel');
distDirs('/middleware');
});
gulp.task('watch', () => {
gulp.watch('./koa.js', () => {
return gulp
.src('./koa.js')
.pipe(babel({ presets: ['@babel/preset-env'] }))
.pipe(uglifyJS())
.pipe(concat('app-buddle.js'))
.pipe(gulp.dest(ROOT));
});
gulp.watch('./controllers/*.js', () => {
const files = fs.readdirSync(__dirname + '/controllers');
files.forEach((item) => {
const controller = require(__dirname + '/controllers/' + item);
if (controller) {
return gulp
.src(`./controllers/${item}`)
.pipe(
babel({
presets: ['es2015'],
plugins: ['@babel/plugin-transform-runtime'],
}),
)
.pipe(uglifyJS())
.pipe(concat(`${item}`))
.pipe(gulp.dest('./controllers/dist/'));
}
});
});
});
gulp.task('default', () => {
console.log('111');
gulp.task('watch');
});