gulpfile.js
2.21 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
var gulp = require('gulp');
var gutil = require('gulp-util');
var ftp = require('gulp-ftp');
var fs = require('fs');
var exec = require('child_process').exec;
var compass = require('gulp-compass');
var jshint = require('gulp-jshint');
var stylish = require('jshint-stylish');
var concat = require('gulp-concat');
var clean = require('gulp-clean');
//获取package.json的配置参数
var config = JSON.parse(fs.readFileSync('./package.json').toString());
var dist_assets_dir = 'dist/'+config.name+'/assets';
var dist_dir = {
js: 'dist/'+config.name+'/'+config.version,
css: 'dist/'+config.name+'/'+config.version,
image: dist_assets_dir+'/images',
font: dist_assets_dir+'/fonts'
};
var ftpConfig = {
host: '58.213.133.26',
user: 'php',
pass: 'yoho9646'
};
//js代码验证
gulp.task('lint',function() {
return gulp.src(['js/*.js','js/**/*.js','!js/plugin/nicescroll.js'])
.pipe(jshint({
"asi": true,
"newcap": true
}))
.pipe(jshint.reporter(stylish));
});
//编译部署compass
gulp.task('compass-dist',['assets'],function() {
gulp.src('sass/**/*.scss')
.pipe(compass({
css: dist_dir.css,
sass: 'sass',
image: dist_dir.image,
font: dist_dir.font,
http_path:'/',
style:'compressed'
}))
.on('error', function(error) {
console.log(error);
this.emit('end');
});
});
//拷贝assets到发布目录
gulp.task('assets',function() {
gulp.src('assets/**')
.pipe(gulp.dest(dist_assets_dir));
});
//打包seajs
gulp.task('spm',['build'],function(cb) {
gulp.src(['js/lib/seajs.js',dist_dir.js+'/index.js'])
.pipe(concat('index.min.js'))
.pipe(gulp.dest(dist_dir.js));
});
//spm build
gulp.task('build',function (cb) {
exec('spm build --include standalone', function(err) {
if (err) return cb(err);
cb();
});
});
//发布到CDN
gulp.task('dist',['compass-dist','spm'], function () {
var ftpstream = ftp(ftpConfig);
return gulp.src('dist/**')
.pipe(ftpstream)
.pipe(gutil.noop());
});
// watch打包js
gulp.task('watch',function () {
gulp.watch(['js/**'],['build']);
});