-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
170 lines (135 loc) · 3.7 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
159
160
161
162
163
164
165
166
167
168
169
/*!
layuiAdmin pro 构建
*/
var pkg = require('./package.json');
var inds = pkg.independents;
var gulp = require('gulp');
var uglify = require('gulp-uglify');
var minify = require('gulp-minify-css');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var replace = require('gulp-replace');
var header = require('gulp-header');
var del = require('del');
var gulpif = require('gulp-if');
var minimist = require('minimist');
//获取参数
var argv = require('minimist')(process.argv.slice(2), {
default: {
ver: 'all'
}
})
//注释
,note = [
// '/** <%= pkg.name %>-v<%= pkg.version %> <%= pkg.license %> License */\n <%= js %>'
,''
,{pkg: pkg, js: ';'}
]
,destDir = './dist' //构建的目标目录
,releaseDir = '../pack/layuiAdmin.pack/'+ pkg.name +'-v' + pkg.version //发行版本目录
//任务
,task = {
//压缩 JS
minjs: function(){
var src = [
'./src/**/*.js'
,'!./src/config.js'
,'!./src/lib/extend/**/*.js'
];
return gulp.src(src).pipe(uglify({
output: {
ascii_only: true //escape Unicode characters in strings and regexps
}
}))
.pipe(header.apply(null, note))
.pipe(gulp.dest(destDir));
}
//压缩 CSS
,mincss: function(){
var src = [
'./src/**/*.css'
]
,noteNew = JSON.parse(JSON.stringify(note));
noteNew[1].js = '';
return gulp.src(src).pipe(minify({
compatibility: 'ie7'
})).pipe(header.apply(null, noteNew))
.pipe(gulp.dest(destDir));
}
//复制文件夹
,mv: function(){
gulp.src('./src/config.js')
.pipe(gulp.dest(destDir));
gulp.src('./src/lib/extend/**/*')
.pipe(gulp.dest(destDir + '/lib/extend'));
gulp.src('./src/style/res/**/*')
.pipe(gulp.dest(destDir + '/style/res'));
return gulp.src('./src/views/**/*')
.pipe(gulp.dest(destDir + '/views'));
}
};
gulp.task('minjs', task.minjs);
gulp.task('mincss', task.mincss);
gulp.task('mv', task.mv);
//清理
gulp.task('clear', function(cb) {
return del(['./dist/*'], cb);
});
//构建核心源文件(发行版)
gulp.task('default', ['clear'], function(){ //命令:gulp
for(var key in task){
task[key]();
}
});
/**
* 开发模式
*/
//清理 src
gulp.task('clearSrc', function(cb) {
return del(['./src/*'], cb);
});
//复制 src
gulp.task('src', ['clearSrc'], function(){
return gulp.src('./dev-src/**/*')
.pipe(gulp.dest('./src'));
});
//构建核心源文件(开发版)
gulp.task('dev', ['clear', 'src'], function(){ //命令:gulp dev
for(var key in task){
task[key]();
}
});
//发行文件
gulp.task('release', function(){ //命令:gulp && gulp release
//复制核心文件
gulp.src('./dist/**/*')
.pipe(gulp.dest(releaseDir + '/dist'));
gulp.src('./src/**/*')
.pipe(gulp.dest(releaseDir + '/src'));
//复制 json
gulp.src('./dev/json/**/*')
.pipe(gulp.dest('./json'))
.pipe(gulp.dest('./start/json'))
.pipe(gulp.dest(releaseDir + '/start/json'));
//复制并转义宿主页面
gulp.src('./dev/index.html')
.pipe(replace(/\<\!-- clear s --\>([\s\S]*?)\<\!-- clear e --\>/, ''))
.pipe(replace('//local.res.layui.com/layui/src', 'layui'))
.pipe(replace("base: '../dev-src/'", "base: '../dist/'"))
.pipe(replace('@@version@@', pkg.version))
.pipe(gulp.dest('./start'))
.pipe(gulp.dest(releaseDir + '/start'));
//复制帮助文件
gulp.src([
'./帮助/*'
]).pipe(gulp.dest(releaseDir));
//复制 gulpfile
gulp.src([
'gulpfile.js'
,'package.json'
]).pipe(gulp.dest(releaseDir));
//复制 layui
return gulp.src('../../../../res/layui/rc/**/*')
.pipe(gulp.dest('./start/layui'))
.pipe(gulp.dest(releaseDir + '/start/layui'))
});