-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathgulpfile.js
More file actions
109 lines (94 loc) · 3.1 KB
/
gulpfile.js
File metadata and controls
109 lines (94 loc) · 3.1 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
// npm install --save-dev gulp gulp-uglify gulp-concat yargs gulp-changed gulp-plumber browser-sync gulp-clean
var gulp = require('gulp');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var changed = require('gulp-changed');
var plumber = require('gulp-plumber');
var clean = require('gulp-clean');
var yargs = require('yargs').argv;
var browserSync = require('browser-sync');
var gulpSequence = require('gulp-sequence');
var srcPath = __dirname + '/src',
distPath = __dirname + '/dist',
bgSrcPath = srcPath + '/scripts/bingo2',
buildPath = distPath + "/scripts/bingo2";
var srcList = ['core.js', 'promise.js', 'event.js', 'observe.js',
'package.js', 'route.js', 'compiles.js',
'service/base.js', 'command/base.js', 'attrs/base.js'];
//var srcList = ['core.js', 'promise.js', 'event.js', 'observe.js',
// 'package.js', 'linkNode.js', 'route.js', 'location.js', 'compiles.js',
// 'service/base.js', 'command/base.js', 'attrs/base.js'];
srcList = srcList.map(function (item) {
return [bgSrcPath , item].join('/');
});
gulp.task('build', gulpSequence('clean', 'build:start'));
gulp.task('clean', function () {
return gulp.src(distPath)
.pipe(clean());
});
gulp.task('build:start', gulpSequence(['build:concat', 'build:copy'], 'build:uglify'));
gulp.task('build:bingojs', function (cp) { gulpSequence('build:concat', 'build:uglify')(cp); });
gulp.task('build:concat', function () {
return gulp.src(srcList)
.pipe(plumber())
.pipe(concat('bingo.js'))
.pipe(gulp.dest(buildPath));
});
gulp.task('build:uglify', function () {
return gulp.src(srcList)
.pipe(plumber())
.pipe(concat('bingo.min.js'))
.pipe(uglify())
.pipe(gulp.dest(buildPath))
.pipe(browserSync.reload({ stream: true }));
});
gulp.task('build:copy', function () {
return gulp.src(['src/**', '!src/scripts/bingo2/**'])
.pipe(plumber())
.pipe(changed(distPath))
.pipe(gulp.dest(distPath))
.pipe(browserSync.reload({ stream: true }));
});
gulp.task('watch', function () {
gulp.watch(['src/**', '!src/scripts/bingo2/**'], ['build:copy']);
gulp.watch('src/scripts/bingo2/**', ['build:bingojs']);
});
gulp.task('server', function () {
yargs.p = yargs.p || 8080;
var index = yargs.n ? '/demo/test.html' : (yargs.t ? '/jasmine/core.html' : '/index.html');
browserSync.init({
server: {
baseDir: "./dist"
},
ui: {
port: yargs.p + 1,
weinre: {
port: yargs.p + 2
}
},
port: yargs.p,
open: "external",
//startPath: '/demo/box.html'
startPath: index
});
});
// 参数说明
// -w: 实时监听
// -s: 启动服务器
// -p: 服务器启动端口,默认8080
gulp.task('default', ['build'], function () {
if (yargs.s) {
gulp.start('server');
}
if (yargs.w) {
gulp.start('watch');
}
});
//gulp.task('default', function () {
// if (yargs.s) {
// gulp.start('server');
// }
// if (yargs.w) {
// gulp.start('watch');
// }
//});