-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
93 lines (85 loc) · 2.73 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
/**
* 组件安装
* npm install gulp-util gulp-imagemin gulp-ruby-sass gulp-minify-css gulp-jshint gulp-uglify gulp-rename gulp-concat gulp-clean gulp-livereload tiny-lr --save-dev
*/
// 引入 gulp及组件
var gulp = require('gulp'),
connect = require('gulp-connect'),
less = require('gulp-less');
// uglify = require('gulp-uglify'),
// concat = require('gulp-concat'),
// // rev = require('gulp-rev-append'),
// imagemin = require('gulp-imagemin'),
// cssmin = require('gulp-minify-css'),
//htmlmin = require('gulp-htmlmin');
var path = {
src : "src/",
css : "src/css/",
js : "src/js/",
scss : "src/scss/",
img : "src/images/",
build : "build"
}
/*gulp.task('concat', function () {
gulp.src('src/js/*.js')
.pipe(concat('main.js'))
.pipe(gulp.dest('dist/js'));
});*/
// gulp.task('jsmin', function () {
// gulp.src('src/js/*.js')
// .pipe(uglify())
// .pipe(gulp.dest('dist/js'));
// });
// gulp.task('testCssmin', function () {
// gulp.src('src/css/*.css')
// .pipe(cssmin())
// .pipe(gulp.dest('dist/css'));
// });
//gulp.task('testImagemin', function () {
// gulp.src('src/image/*.{png,jpg,gif,ico}')
// .pipe(imagemin())
// .pipe(gulp.dest('dist/image'));
//});
/*gulp.task('testHtmlmin', function () {
var options = {
removeComments: true,//清除HTML注释
collapseWhitespace: true,//压缩HTML
collapseBooleanAttributes: true,//省略布尔属性的值 <input checked="true"/> ==> <input />
removeEmptyAttributes: true,//删除所有空格作属性值 <input id="" /> ==> <input />
removeScriptTypeAttributes: true,//删除<script>的type="text/javascript"
removeStyleLinkTypeAttributes: true,//删除<style>和<link>的type="text/css"
minifyJS: true,//压缩页面JS
minifyCSS: true//压缩页面CSS
};
gulp.src('src/*.html')
.pipe(htmlmin(options))
.pipe(gulp.dest('dist/'));
});*/
// gulp.task('testRev',function(){
// gulp.src('src/*.html')
// .pipe(rev())
// .pipe(gulp.dest('dist/'))
// })
gulp.task('testLess', function () {
gulp.src('src/css/style.less')
.pipe(less())
.pipe(gulp.dest('src/css'));
});
//gulp.task('default', [/*'concat',*/ 'jsmin','testCssmin',/*'testHtmlmin',*/'testRev']);
gulp.task('watch', function() {
gulp.watch(path.src + '**/*.*',['testLess','reload-dev']);
});
gulp.task('connectDev', function() {
connect.server({
root: path.src,
port: 8000,
livereload: true
});
});
//reload server
gulp.task('reload-dev',function() {
gulp.src(path.src + '**/*.*')
.pipe(connect.reload());
});
//测试服务器
gulp.task('default', ['connectDev', 'watch','testLess']);