-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
118 lines (108 loc) · 2.91 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
var del = require('del');
var gulp = require('gulp');
var webserver = require('gulp-webserver');
var sass = require('gulp-sass')
var babel = require('gulp-babel')
var autoprefixer = require("gulp-autoprefixer");
var cssmin = require("gulp-cssmin");
var htmlmin = require("gulp-htmlmin");
var jsmin = require("gulp-jsmin");
var jsugify = require("gulp-uglify");
var { series } = require('gulp');
var phpserver = require('gulp-connect-php');
//编译sass任务
var scssHandler = ()=>{
return gulp
.src("./src/sass/*.scss")
.pipe(sass())
.pipe(gulp.dest("./src/css"))
}
//打包任务
var cssminHandler = ()=>{
return gulp
.src("./src/css/*.css")
.pipe(autoprefixer())
.pipe(cssmin())
.pipe(gulp.dest("./dist/css"))
}
var jsminHandler = ()=>{
return gulp
.src("./src/js/*.js")
.pipe(babel())
.pipe(jsmin())
.pipe(gulp.dest("./dist/js"))
}
var htmlminHandler = ()=>{
return gulp
.src("./src/pages/*.html")
.pipe(htmlmin())
.pipe(gulp.dest("./dist/pages"))
}
var delHandler = ()=>{
return del(['./dist'])
}
// 服务器测试 已弃用
var testServer = ()=>{
return gulp
.src('./src')
.pipe(webserver({
port:8000,
open:'./pages/user.html',
livereload:true,
proxies:[
{
source:'/smartisan_hotword',
target:'https://shopapi.smartisan.com'
},
{
source:'/smartisan_second_nav',
target:'https://shopapi.smartisan.com'
},
{
source:'/smartisan_goods_list',
target:'https://shopapi.smartisan.com'
},
{
source:'/home',
target:'https://shopapi.smartisan.com'
},
{
source:'/smartisan_cart',
target:'https://shopapi.smartisan.com/product/spus'
},
{
source:'/myphpuser',
target:'http://localhost:666/php/user.php'
},
{
source:'/myphpcart',
target:'http://localhost:666/php/cart.php'
}
]
}))
}
var phpHandler = ()=>{
return gulp.src("./src")
.pipe(
phpserver({
port:8001,
open:true,
bin:"/Applications/MAMP/bin/php/php7.4.2/bin"
})
)
}
var watchHandler = ()=>{
gulp.watch('./',testServer)
}
module.exports.default = gulp.series(
delHandler,
scssHandler,
gulp.parallel(
htmlminHandler,
cssminHandler,
jsminHandler
),
testServer,
watchHandler,
phpHandler
)