-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
123 lines (111 loc) · 3.57 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
115
116
117
118
119
120
121
122
123
(function () {
'use strict';
let gulp = require('gulp'),
babel = require('gulp-babel'),
plumber = require('gulp-plumber'),
uglify = require('gulp-uglify'),
concat = require('gulp-concat'),
cssmin = require('gulp-clean-css'),
less = require('gulp-less');
const arr = [
{name: 'admin', file: ['public/app/admin/**/*.js']},
{name: 'app', file: 'public/app/admin/*.js'},
{name: 'main', file: 'public/app/admin/main/*.js'},
{name: 'information', file: 'public/app/admin/information/**/*.js'},
{name: 'person', file: 'public/app/admin/person/**/*.js'},
{name: 'car', file: 'public/app/admin/car/**/*.js'},
{name: 'common', file: 'public/app/common/**/*.js'},
];
//****** DEV Tasks *******//
for (let i = 0; i < arr.length; i++) {
gulp.task(arr[i].name + '-dev', ()=> {
return gulp.src(arr[i].file)
.pipe(require('gulp-jshint')())
.pipe(concat(arr[i].name + '.min.js'))
.pipe(gulp.dest('./public/dist'))
.pipe(require('gulp-livereload')());
});
}
//*********less dev*********//
let lessArr = [
{name: 'app-less', file: 'public/app/less/**/*.less'}
];
for (let i = 0; i < lessArr.length; i++) {
gulp.task(lessArr[i].name + '-dev', ()=> {
return gulp.src(lessArr[i].file)
.pipe(less())
.pipe(concat(lessArr[i].name + '.min.css'))
.pipe(gulp.dest('./public/dist/css'))
.pipe(require('gulp-livereload')());
});
}
//******* PRODUCTION Task ************//
for (let i = 0; i < arr.length; i++) {
gulp.task(arr[i].name, ()=> {
return gulp.src(arr[i].file)
.pipe(babel({
plugins: [
'@babel/plugin-transform-for-of'
],
//presets: ['env']
presets: ['@babel/env']
}))
.pipe(uglify({mangle: false}))
.pipe(concat(arr[i].name + '.min.js'))
.pipe(gulp.dest('./public/dist'));
});
}
//*********Production less*********//
for (let i = 0; i < lessArr.length; i++) {
gulp.task(lessArr[i].name, ()=> {
return gulp.src(lessArr[i].file)
.pipe(plumber())
.pipe(less())
.pipe(cssmin())
.pipe(concat(lessArr[i].name + '.min.css'))
.pipe(gulp.dest('./public/dist/css'))
.pipe(plumber.stop());
});
}
// pug Task
gulp.task('pug', () => gulp.src(['public/app/**/*.pug', 'server/views/*.pug']));
// clean Task
gulp.task('clean', () => gulp.src('./public/dist/*').pipe(require('gulp-clean')()));
gulp.task('watch', () => {
//require('gulp-livereload').listen();
require('gulp-livereload').listen(35720, function(err) {
if(err){
console.log(err);
}
});
for (let i = 0; i < arr.length; i++) {
gulp.watch(arr[i].file, {usePolling: true}, gulp.parallel(arr[i].name + '-dev'));
}
for (let i = 0; i < lessArr.length; i++) {
gulp.watch(lessArr[i].file, {usePolling: true}, gulp.parallel(lessArr[i].name + '-dev'));
}
gulp.watch(['public/app/**/*.pug', 'server/views/*.pug'], gulp.parallel('pug')).on('change', file => {
gulp.src(file).pipe(require('gulp-livereload')());
});
});
let taskDev = [];
let task = [];
for (let i = 0; i < lessArr.length; i++) {
taskDev.push(lessArr[i].name + '-dev');
task.push(lessArr[i].name);
}
for (let i = 0; i < arr.length; i++) {
taskDev.push(arr[i].name + '-dev');
task.push(arr[i].name);
}
let env = process.env.NODE_ENV || 'dev';
if(env == 'dev'){
gulp.task('default', gulp.series('clean', gulp.parallel(taskDev), 'watch'));
}else{
gulp.task('default',gulp.parallel(task));
}
//gulp.task('default', gulp.series('clean', gulp.parallel(taskDev), 'watch'));
//gulp.task('default',gulp.parallel(task));
//gulp.task('heroku:staging', gulp.parallel(task));
//gulp.task('heroku:production', gulp.parallel(task));
}());