-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
99 lines (83 loc) · 3.04 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
'use strict';
const gulp = require('gulp'),
$ = require('gulp-load-plugins')();
//css 合并 压缩 md5
gulp.task('css', function(){
return gulp.src('./public/src/css/!(common)/*.css')
.pipe($.cssimport({}))
.pipe($.autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
.pipe($.cssmin())
.pipe($.rev())
.pipe(gulp.dest('./public/dist/css'))
.pipe($.rev.manifest())
.pipe($.rename('css-mainfest.json'))
.pipe(gulp.dest('./public/dist/rev/css'));
});
//清除原来的内容
gulp.task("cleancss", function(){
return gulp.src('./public/dist/css')
.pipe($.clean());
});
gulp.task('seajs', ['index', 'about/index']);
gulp.task('index', function(){
return gulp.src("public/src/js/{index,}/index_main.js")
.pipe($.seajsCombo({
map:{
'/public/src/js/index/index.js': 'D:/wamp/www/hxe/public/src/js/index/index.js'
}
}))
.pipe(gulp.dest('D:/wamp/www/hxe/public/temp'))
});
gulp.task('about/index', function(){
return gulp.src("public/src/js/{about,}/index_main.js")
.pipe($.seajsCombo({
map:{
'/public/src/js/about/index.js': 'D:/wamp/www/hxe/public/src/js/about/index.js'
}
}))
.pipe(gulp.dest('D:/wamp/www/hxe/public/temp'))
});
gulp.task('js', ['seajs'], function(){
return gulp.src("D:/wamp/www/hxe/public/temp/*/*.js")
.pipe($.uglify())
.pipe($.rev())
.pipe(gulp.dest('./public/dist/js'))
.pipe($.rev.manifest())
.pipe($.rename('js-manifest.json'))
.pipe(gulp.dest('./public/dist/rev/js'))
});
//清除原来的内容
gulp.task("cleanJs", function(){
return gulp.src('./public/dist/js')
.pipe($.clean());
});
//html 压缩
gulp.task('rev',function () {
var options = {
removeComments: true, //清除HTML注释
collapseWhitespace: true, //压缩HTML
collapseBooleanAttributes: true, //省略布尔属性的值 <input checked="true"/> ==> <input checked />
removeEmptyAttributes: true, //删除所有空格作属性值 <input id="" /> ==> <input />
removeScriptTypeAttributes: true, //删除<script>的type="text/javascript"
removeStyleLinkTypeAttributes: true, //删除<style>和<link>的type="text/css"
minifyJS: true, //压缩页面JS
minifyCSS: true //压缩页面CSS
};
return gulp.src(['./public/dist/rev/*/*.json', './app/view/*/*.html'])
.pipe($.revCollector({
replaceReved: true,
dirReplacements: {
'/src/css': '/dist/css/',
'/src/js/': '/dist/js/'
}
}))
.pipe($.htmlmin(options))
.pipe(gulp.dest('./app/view_build'));
});
gulp.task("cleanhtml", function(){
return gulp.src('./app/view_build')
.pipe($.clean());
});
gulp.task('default', ['cleancss','cleanJs', 'cleanhtml'], function(){
gulp.start('css','js','rev');
});