-
Notifications
You must be signed in to change notification settings - Fork 1
/
Gulpfile.js
97 lines (82 loc) · 2.83 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
var gulp = require('gulp');
var amdOptimize = require('amd-optimize');
var concat = require('gulp-concat');
var less = require('gulp-less');
var path = require('path');
var rename = require('gulp-rename');
var dirSync = require('gulp-directory-sync');
var minifyCSS = require('gulp-minify-css');
var uglify = require('gulp-uglify');
var template = require('gulp-lazy-tpl');
var rm = require('gulp-rm');
var connect = require('gulp-connect');
gulp.task('default', ['demo:sync']);
gulp.task('build', ['style:build', 'script:build'], function() {});
gulp.task('style:build', ['style:less', 'style:copy-lib', 'style:copy-img', 'style:copy-font'], function() {});
gulp.task('script:build', ['script:copy-lib', 'scripts:minify'], function() {});
// 编译脚本
gulp.task('scripts:compile', ['scripts:template'], function() {
return gulp.src('src/js/**/*.js')
.pipe(amdOptimize('moe', {wrapShim : true}))
.pipe(concat('moe.js'))
.pipe(gulp.dest('dist/js'));
});
gulp.task('scripts:template', function() {
gulp.src('./src/js/tpl/**/*.js', {read : false})
.pipe(rm({async : false}));
return gulp.src('./src/js/tpl/**/*.html')
.pipe(template('doT', {}))
.pipe(rename({extname : '.js'}))
.pipe(gulp.dest('./src/js/tpl/'));
});
// 压缩脚本
gulp.task('scripts:minify', ['scripts:compile'], function() {
return gulp.src('dist/js/moe.js')
.pipe(concat('moe.min.js'))
// .pipe(uglify())
.pipe(gulp.dest('dist/js'));
});
// 处理less文件并压缩输出
gulp.task('style:less', function() {
return gulp.src('./src/less/moe.less')
.pipe(less({paths : [path.join(__dirname, 'less', 'includes')]}))
.pipe(minifyCSS())
.pipe(rename('css/style.min.css'))
.pipe(gulp.dest('./dist'));
});
// 将依赖的base样式文件复制到输出目录
gulp.task('style:copy-lib', function() {
return gulp.src('./src/css/*.css')
.pipe(gulp.dest('dist/css/'));
});
// 复制依赖的字体文件
gulp.task('style:copy-font', function() {
return gulp.src('./src/fonts/*')
.pipe(gulp.dest('dist/fonts'));
});
// 复制图片
gulp.task('style:copy-img', function() {
return gulp.src('./src/img/*')
.pipe(gulp.dest('dist/img'));
});
// 复制依赖的脚本文件
gulp.task('script:copy-lib', function() {
return gulp.src('./src/js/lib/*.js')
.pipe(gulp.dest('dist/js/lib'));
});
// 同步输出文件到Demo目录
gulp.task('demo:sync', ['build'], function() {
gulp.src('')
.pipe(dirSync('src/html', 'demo', {printSummary : true}))
.pipe(dirSync('dist', 'demo/assets', {printSummary : true}))
.pipe(connect.reload())
.on('error', function(e) {
console.log(e);
});
});
gulp.task('connect', function() {
connect.server({
root: './',
livereload: true
});
});