gulpfile.js
2.83 KB
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
var gulp = require('gulp');
var gutil = require('gulp-util');
var ftp = require('gulp-ftp');
var fs = require('fs');
var uglify = require('gulp-uglify'),
rename = require('gulp-rename');
var concat = require('gulp-concat');
var exec = require('child_process').exec;
var compass = require('gulp-compass');
var jshint = require('gulp-jshint');
var stylish = require('jshint-stylish');
//获取package.json的配置参数
var config = JSON.parse(fs.readFileSync('./package.json').toString());
var dist_assets_dir = 'dist/'+config.name+'/assets';
var dist_seajs_dir='dist/'+config.name+'/'+config.version+"/min";
var dist_js_dir='dist/'+config.name+'/'+config.version;
var source_js_dir='js/';
var dist_dir =
{
css: 'dist/'+config.name+'/'+config.version,
image: dist_assets_dir+'/images',
font: dist_assets_dir+'/fonts'
};
var ftpConfig =
{
host: '218.94.77.166',
user: 'php',
pass: 'yoho9646'
};
gulp.task('default',function(){
});
//compass的watch
gulp.task('cw',function(cb)
{
exec('compass watch', function(err)
{
if (err) return cb(err);
cb();
});
});
//js代码验证
gulp.task('lint',function()
{
return gulp.src(['js/*.js','js/**/*.js'])
.pipe(jshint())
.pipe(jshint.reporter(stylish));
});
//编译部署compass
gulp.task('compass-dist',['assets'],function()
{
gulp.src('sass/scss/**')
.pipe(compass(
{
css: dist_dir.css,
sass: 'sass/scss',
image: dist_dir.image,
font: dist_dir.font,
style:'compressed'
}))
.on('error', function(error)
{
console.log(error);
this.emit('end');
});
});
//执行spm的build
gulp.task('spm',function(cb)
{
exec('spm build --include all', function(err)
{
if (err) return cb(err);
cb();
});
});
gulp.task('js',['seajs','copy','concat'],function(){
console.log("压缩合并完成");
});
gulp.task('seajs',function(){
gulp.src('js/util/seajs_dev.js')
.pipe(uglify())
.pipe(rename('seajs.min.js'))
.pipe(gulp.dest(dist_seajs_dir));
});
gulp.task('copy',function(){
gulp.src(dist_js_dir+'/index.js')
.pipe(rename('z_index.js'))
.pipe(gulp.dest(dist_seajs_dir));
gulp.src(source_js_dir+'/yas.js')
.pipe(gulp.dest(dist_js_dir));
});
gulp.task('concat',function(){
gulp.src(dist_seajs_dir+'/*.js')
.pipe(concat('index.min.js'))
.pipe(gulp.dest(dist_js_dir));
});
//拷贝assets到发布目录
gulp.task('assets',function()
{
gulp.src('assets/**')
.pipe(gulp.dest(dist_assets_dir));
});
//发布到CDN
gulp.task('dist',['compass-dist'], function ()
{
var ftpstream = ftp(ftpConfig);
return gulp.src('dist/**')
.pipe(ftpstream)
.pipe(gutil.noop());
});
//发布到CDN
gulp.task('comp',['compass-dist','js'], function ()
{
//编译到本地
console.log("将文件编译到本地!!!!");
});