-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
67 lines (59 loc) · 1.8 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
var gulp = require('gulp'),
open = require("gulp-open"),
connect = require('gulp-connect');
var tmodjs = require('gulp-tmod');
var dest = __dirname, //本地开发时的监测目录,部署时用dist目录
port = 8088,
watchPath = [ //监测的文件路径
dest + "/html/**/*.html",
dest + "/js/**/*.js",
dest + "/css/**/*.css"
],
openPath = dest + "/html/index.html", //用浏览器打开的文件路径
openOption = {
url: "http://127.0.0.1:" + port + "/html/index.html?code=WXFAKECODE#/"
},
openOption2 = {
url: "http://127.0.0.1:" + port + "/html/index.html?code=WXFAKECODE#/service/1/cart"
};
//用浏览器打开dest目录下的index.html文件
gulp.task('open', /*['server'],*/ function() {
gulp.src(openPath)
.pipe(open("", openOption));
// gulp.src(openPath)
// .pipe(open("", openOption2));
});
/*
在dist目录下启动静态文件服务器
插件doc: https://github.com/AveVlad/gulp-connect
*/
gulp.task('connect', function() {
connect.server({
port: port,
root: dest,
directoryListing: true,
livereload: true
});
});
gulp.task('reload-html', function() {
gulp.src(watchPath)
.pipe(connect.reload());
});
//监测dist目录中的变动,并触发reload
gulp.task('connect-watch', function() {
gulp.watch([watchPath], ['reload-html']);
});
gulp.task('default', ['connect', 'open', 'connect-watch']);
var tplPath = './src/tpl/src/**/*.html';
gulp.task('tmod', function() {
return gulp.src(tplPath)
.pipe(tmodjs({
base: './src/tpl/src',
combo: true,
output: './src/tpl/dist'
}));
});
//监测tpl目录中的变动,并触发tmod
gulp.task('tmod-watch', function() {
gulp.watch([tplPath], ['tmod']);
});