-
Notifications
You must be signed in to change notification settings - Fork 28
/
gulpfile.js
123 lines (110 loc) · 2.79 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
var gulp = require('gulp');
var del = require('del');
var jshint = require('gulp-jshint');
var stylish = require('jshint-stylish');
var less = require('gulp-less');
var usemin = require('gulp-usemin');
var uglify = require('gulp-uglify');
var minifyCss = require('gulp-minify-css');
var rev = require('gulp-rev');
var concat = require('gulp-concat');
var html2js = require('gulp-html2js');
var replace = require('gulp-replace');
var rename = require("gulp-rename");
var connect = require('gulp-connect');
var runSequence = require('run-sequence');
var html2jsFileName;
gulp.task('clean', function(cb) {
return del([
'./build',
'./assets/css'
], cb);
});
gulp.task('less', function() {
return gulp.src('assets/less/materialdrive.less')
.pipe(less({
modifyVars: {
'@image-asset-path': '"../assets/images"',
'@fa-font-path': '"../assets/fonts"'
}
}))
.pipe(gulp.dest('assets/css'));
});
gulp.task('jshint', function() {
return gulp.src([
'*.js',
'app/**/*.js'
])
.pipe(jshint())
.pipe(jshint.reporter(stylish));
});
gulp.task('html2js', function() {
return gulp.src('app/**/*.html')
.pipe(html2js('app.tpls.js', {
name: 'materialDrive.tpls'
}))
.pipe(uglify())
.pipe(rev())
.pipe(rename(function(data) {
html2jsFileName = data.basename + data.extname;
}))
.pipe(gulp.dest('build/js'));
});
gulp.task('copyAssets', function () {
gulp.src('bower_components/font-awesome/fonts/*')
.pipe(gulp.dest('build/assets/fonts'));
gulp.src('assets/images/**')
.pipe(gulp.dest('build/assets/images'));
gulp.src('favicon.ico')
.pipe(gulp.dest('build/'));
return gulp.src(['index.html'])
.pipe(replace('<!-- app.tpls.js -->', '<script src="js/' + html2jsFileName + '"></script>'))
.pipe(gulp.dest('build'));
});
gulp.task('usemin', function() {
return gulp.src('build/index.html')
.pipe(usemin({
css: [
minifyCss(),
rev()
],
libjs: [
uglify(),
rev()
],
appjs: [
uglify(),
rev()
],
inlinejs: [
uglify()
],
inlinecss: [
minifyCss(),
'concat'
]
}))
.pipe(gulp.dest('build/'));
});
gulp.task('default', function(cb) {
runSequence('build', cb);
});
gulp.task('build', function(cb) {
runSequence('jshint', 'clean', 'less', 'html2js', 'copyAssets', 'usemin', cb);
});
gulp.task('dev', function (cb) {
runSequence('dev_less', 'connect', 'watch', cb);
});
gulp.task('connect', function () {
connect.server({
port: 3000
});
});
gulp.task('dev_less', function() {
return gulp.src('assets/less/materialdrive.less')
.pipe(less())
.pipe(gulp.dest('assets/css'));
});
gulp.task('watch', function() {
return gulp.watch('assets/less/*.less', ['dev_less']);
});