-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathgulpfile.js
104 lines (97 loc) · 2.69 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
var gulp = require('gulp');
var uglify = require('gulp-uglify');
var minifyCss = require('gulp-minify-css');
var minifyHTML = require('gulp-minify-html');
var sourcemaps = require('gulp-sourcemaps');
var babel = require('gulp-babel');
var less = require('gulp-less');
var connect = require('gulp-connect');
var clean = require('gulp-clean');
var webpack = require('gulp-webpack');
var vue = require('vue-loader');
// clear
gulp.task('clean', function(){
gulp.src('./build/*.*')
.pipe(clean({force: true}));
});
// copy libs
gulp.task('copylibs', function () {
gulp.src('./src/lib/*.*')
.pipe(gulp.dest('build/lib'));
});
//
gulp.task('vue', function() {
gulp.src('src/app.js')
.pipe(webpack({
output: {
filename: 'app.js'
},
module: {
loaders: [
{ test: /\.vue$/, loader: 'vue'}
]
},
babel: {
presets: ['es2015'],
plugins: ['transform-runtime']
}
}))
.pipe(gulp.dest('build/vue'));
});
// 压缩html
gulp.task('minhtml', function () {
gulp.src('./src/*.html')
.pipe(minifyHTML({comments:false,spare:false,quotes:true}))
.pipe(gulp.dest('build/'));
});
// less 解析
gulp.task('less', function () {
gulp.src('./src/styles/*.less')
.pipe(sourcemaps.init())
.pipe(less())
.pipe(sourcemaps.write('./maps'))
.pipe(gulp.dest('build/styles'));
});
// es6 解析
gulp.task('babel', function () {
gulp.src('./src/scripts/*.js')
.pipe(sourcemaps.init())
.pipe(babel({
presets: ['es2015']
}))
.pipe(sourcemaps.write('./maps'))
.pipe(gulp.dest('build/scripts'));
});
// less解析
gulp.task('lessAndMini', function () {
gulp.src('./src/styles/*.less')
.pipe(less())
.pipe(minifyCss())
.pipe(gulp.dest('build/styles'));
});
// es6 解析
gulp.task('babelAndMini', function () {
gulp.src('./src/scripts/*.js')
.pipe(babel({
presets: ['es2015']
}))
.pipe(uglify())
.pipe(gulp.dest('build/scripts'));
});
// 启动服务器
gulp.task('connect', function () {
connect.server({
root: './build',
port: 3000,
livereload: true
});
});
// 监听文件变化
gulp.task('watch', function () {
gulp.watch(['./src/*.html'], ['minhtml']);
gulp.watch(['./src/scripts/*.js'], ['babel']);
gulp.watch(['./src/styles/*.less'], ['less']);
gulp.watch(['./src/vue/*.vue'], ['vue']);
})
gulp.task('default', ['clean', 'copylibs', 'vue', 'minhtml', 'lessAndMini', 'babelAndMini']);
gulp.task('dev', ['clean', 'copylibs', 'vue', 'minhtml', 'less', 'babel', 'connect', 'watch']);