-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
67 lines (58 loc) · 1.86 KB
/
gulpfile.babel.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
import gulp from 'gulp';
import gulpSequence from 'gulp-sequence';
import header from 'gulp-header';
import less from 'gulp-less';
import postcss from 'gulp-postcss';
import reporter from 'postcss-reporter';
import autoprefixer from 'autoprefixer';
import stylelint from 'stylelint';
import babel from 'gulp-babel';
import uglify from 'gulp-uglify';
const explanatoryNotes = '/*前端组--南海波*/\n';
// 源文件地址
const lessPath = 'dev/less/*.less';
const jsPath = 'dev/js/*.js';
const imagePath = 'dev/image/*.+(png|jpg|gif|svg)';
// 编译后路径
const distPath = 'static/';
// Less 解析
gulp.task('less', function() {
const plugins = [
stylelint({
"rules":{
"color-no-invalid-hex":true,//颜色色值
"declaration-colon-space-before":"never",//冒号前空格
"declaration-colon-space-after":"always",//冒号后空格
"indentation": 4,//缩进
"number-leading-zero":"always",//少于1时前导0
}
}),
autoprefixer({browsers: ['last 2 version']}),
]
return gulp.src(lessPath)
.pipe(less())
.pipe(postcss(plugins),reporter({clearMessages:true}))
.pipe(header(explanatoryNotes))
.pipe(gulp.dest(distPath + 'css'))
})
// js 解析
gulp.task('scripts', function() {
return gulp.src(jsPath)
.pipe(babel())
// .pipe(uglify({compress:{properties:false},output:{'quote_keys':true}})) // 压缩
.pipe(header(explanatoryNotes))
.pipe(gulp.dest(distPath + 'js'))
})
// images
gulp.task('images', function() {
return gulp.src(imagePath)
.pipe(gulp.dest(distPath + 'image'));
})
// 监听
gulp.task('watch', function() {
gulp.watch(lessPath, ['less']);
gulp.watch(imagePath, ['images']);
gulp.watch(jsPath,['scripts']);
})
gulp.task('build',gulpSequence('scripts','images','less',['watch']));
gulp.task('default', ['build']);