-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
54 lines (42 loc) · 1.13 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
const gulp = require('gulp');
const path = require('path');
const sass = require('gulp-sass')(require('sass'));
const cleanCSS = require('gulp-clean-css');
const rename = require('gulp-rename');
const tap = require('gulp-tap');
/**
* sass globs
*/
const sassGlobs = ['./modules/**/*.scss'];
/**
* sassSpecifyFile
*
* sass 编译指定的文件
*/
function sassSpecifyFile(filePath) {
let dirPath = path.dirname(filePath);
return gulp.src(filePath)
.pipe(sass().on('error', sass.logError))
.pipe(cleanCSS({compatibility: 'ie8'}))
.pipe(rename({extname: '.wxss'}))
.pipe(gulp.dest(dirPath));
}
/**
* sass (所有文件)编译任务
*/
function sassTask(cb) {
gulp.src(sassGlobs).pipe(tap(function(file, t) { return sassSpecifyFile(file.path); }));
cb();
}
/**
* sass 新增和更改监听任务
*/
function sassWatchTask(cb) {
let sassWatcher = gulp.watch(sassGlobs);
sassWatcher.on('add', function(path) { sassSpecifyFile(path); });
sassWatcher.on('change', function(path) { sassSpecifyFile(path); });
cb();
}
exports.default = sassTask;
exports.sass = sassTask;
exports['sass:watch'] = sassWatchTask;