-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
107 lines (98 loc) · 2.31 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
var map = require('map-stream');
var gulp = require('gulp');
var autoprefixer = require('gulp-autoprefixer');
var uglify = require('gulp-uglify');
var minifyCSS = require('gulp-minify-css');
var Duo = require('duo');
var livereload = require('gulp-livereload');
var imagemin = require('gulp-imagemin');
var pngquant = require('imagemin-pngquant');
/*
* Watch
*/
gulp.task('watch', function() {
gulp.watch(__dirname+'/assets/src/js/**/*.js', ['js']);
gulp.watch(__dirname+'/assets/src/css/**/*.css', ['css']);
});
var jsFiles = ['assets/src/js/app.js', 'assets/src/js/admin/admin.js', 'assets/src/js/mobile/mobile.js'];
var cssFiles = ['assets/src/css/style.css', 'assets/src/css/mobile.css'];
/*
* DEFAULT
*/
gulp.task('js', function() {
gulp.src(jsFiles)
.pipe(duo())
.pipe(gulp.dest('assets/public'))
.pipe(livereload());
});
gulp.task('css', function() {
gulp.src(cssFiles)
.pipe(duo())
.pipe(autoprefixer())
.pipe(gulp.dest('assets/public'))
.pipe(livereload());
});
/*
* PROD
*/
gulp.task('js-prod', function() {
gulp.src(jsFiles)
.pipe(duoProd())
.pipe(uglify())
.pipe(gulp.dest('assets/public'));
});
gulp.task('css-prod', function() {
gulp.src(cssFiles)
.pipe(duoProd())
.pipe(autoprefixer())
.pipe(minifyCSS())
.pipe(gulp.dest('assets/public'));
});
/*
* Default
*/
gulp.task('default', ['js', 'css', 'watch']);
/*
* Prod
*/
gulp.task('prod', ['js-prod', 'css-prod']);
/*
* image min
*/
gulp.task('image', function () {
return gulp.src('./assets/src/imgs/**/*')
.pipe(imagemin({
optimizationLevel: 5,
progressive: true,
svgoPlugins: [{removeViewBox: false}],
use: [pngquant()]
}))
.pipe(gulp.dest('./assets/public/imgs/'));
});
/*
* Duo
*/
function duo() {
return map(function (file, fn) {
Duo(process.cwd())
.development(true)
.entry(file.path)
.run(function (err, src) {
if (err) return fn(err);
file.contents = new Buffer(src);
fn(null, file);
});
});
};
function duoProd() {
return map(function (file, fn) {
Duo(process.cwd())
.cache(false)
.entry(file.path)
.run(function (err, src) {
if (err) return fn(err);
file.contents = new Buffer(src);
fn(null, file);
});
});
};