-
Notifications
You must be signed in to change notification settings - Fork 4
/
gulpfile.js
158 lines (121 loc) · 4.42 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
var gulp = require('gulp');
var ect = require('gulp-ect'); // ect模板
var htmlmin = require('gulp-htmlmin'); // html压缩
var cleanCSS = require('gulp-clean-css'); //css 压缩
var uglify = require('gulp-uglify'); // js压缩
var RevAll = require('gulp-rev-all'); // 防止css缓存
var useref = require('gulp-useref'); // css,js 合并
var rename = require("gulp-rename"); // 文件重命名
var clean = require('gulp-clean'); // 删除文件
var gulpif = require('gulp-if'); // Conditionally run a task
var rev = require('gulp-rev-hash'); // 防止html缓存
gulp.task('copy-conf', function () {
gulp.src('./conf.js')
.pipe(gulp.dest('build/'));
});
gulp.task('copy-pics', ['copy-conf'], function () {
gulp.src(['pics/*', 'pics/**/*'])
.pipe(gulp.dest('build/pics/'));
});
gulp.task('copy-fonts', ['copy-pics'], function () {
var sources = ['fonts/*'];
gulp.src(sources)
.pipe(gulp.dest('build/fonts'));
});
gulp.task('html-replace', function () {
var revAll = new RevAll({dontRenameFile: ['.html'], dontUpdateReference: ['.html']});
return gulp.src('./common.html')
.pipe(gulpif('*.js', uglify()))
.pipe(gulpif('*.css', cleanCSS()))
.pipe(useref())
.pipe(revAll.revision())
.pipe(gulp.dest('build/replace'))
.pipe(revAll.manifestFile())
.pipe(gulp.dest('build/replace'));
});
gulp.task('compressjs',['html-replace'], function() {
return gulp.src('build/replace/js/*.js')
.pipe(uglify())
.pipe(gulp.dest('build/replace/js/'));
});
gulp.task('copy-common_views', ['compressjs'], function () {
var sources = ['common_views/*'];
gulp.src(sources )
.pipe(gulp.dest('build/replace/common_views'));
});
gulp.task('copy-static', ['copy-common_views'] ,function () {
var sources = ['static_views/*','static_views/**/*'];
gulp.src(sources)
.pipe(gulp.dest('build/replace/static_views'));
});
gulp.task('build',['copy-static']);
gulp.task('ectHtml', function(){
var rootPath = './build/replace/static_views/';
var relativePathArray = ['*.html', 'solution/*.html', 'companyapp/*.html', 'scene/*.html', 'about/*.html', 'products/*.html'];
var absolutePathArray = [];
for(var i=0; i < relativePathArray.length; i++) {
absolutePathArray.push(rootPath + relativePathArray[i]);
}
return gulp.src(absolutePathArray, {read: false})
.pipe(ect({ext: '.html'}))
.pipe(htmlmin({collapseWhitespace: true}))
.pipe(gulp.dest('build/'));
});
gulp.task('copy-js',['ectHtml'] ,function() {
var sources = './build/replace/js/*';
gulp.src(sources)
.pipe(gulp.dest('build/js'));
});
gulp.task('copy-css',['copy-js'],function() {
var sources = './build/replace/css/*';
gulp.src(sources)
.pipe(gulp.dest('build/css'));
});
gulp.task('copy-application', ['copy-css'], function () {
gulp.src('./application.html')
.pipe(gulp.dest('build/'))
});
gulp.task('rev',['copy-application'], function () {
gulp.src('build/*.html')
.pipe(rev())
.pipe(gulp.dest('build/'))
});
gulp.task('clean', function (cb) {
var sources = 'build/replace';
return gulp.src(sources, {read: false})
.pipe(clean());
});
gulp.task('default',['copy-fonts','rev'] );
// 开发测试
gulp.task('copy-cssdev', function () {
gulp.src(['css/*'])
.pipe(gulp.dest('dev/css'));
});
gulp.task('copy-jsdev',['copy-cssdev'], function () {
gulp.src(['conf.js','common.js','service.js', 'starfield.js'])
.pipe(gulp.dest('dev/'));
});
gulp.task('copy-picsdev', ['copy-jsdev'], function () {
gulp.src(['pics/*', 'pics/**/*'])
.pipe(gulp.dest('dev/pics/'));
});
gulp.task('copy-fontsdev', ['copy-picsdev'], function () {
var sources = ['fonts/*'];
gulp.src(sources)
.pipe(gulp.dest('dev/fonts'));
});
gulp.task('copy-application-dev', ['copy-fontsdev'], function () {
gulp.src('application.html')
.pipe(gulp.dest('dev/'))
});
gulp.task('dev',['copy-application-dev'], function(){
var rootPath = 'static_views/';
var relativePathArray = ['*.html', 'solution/*.html', 'companyapp/*.html', 'scene/*.html', 'about/*.html', 'products/*.html'];
var absolutePathArray = [];
for(var i=0; i < relativePathArray.length; i++) {
absolutePathArray.push(rootPath + relativePathArray[i]);
}
return gulp.src(absolutePathArray)
.pipe(ect({ext: '.html'}))
.pipe(gulp.dest('dev/'));
});