-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
74 lines (67 loc) · 1.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
const gulp = require('gulp')
const del = require('del')
const sass = require('gulp-sass')
const replace = require('gulp-replace')
const rename = require('gulp-rename')
const minimist = require('minimist')
const gulpSequence = require('gulp-sequence')
const knownOptions = {
string: 'env',
default: { env: process.env.NODE_ENV || 'dev' }
};
const options = minimist(process.argv.slice(2), knownOptions)
const path = {
src: {
all: 'src/**/*',
scss: 'src/**/*.scss',
js: 'src/**/*.js',
wxml: 'src/**/*.wxml',
json: 'src/**/*.json'
},
dev: 'example/components',
production: 'dist/'
}
function runBuild (cb) {
gulpSequence(
'component_cleaner',
'sass_compiler',
'component_carrier',
cb
)((err) => {
if (err) {
console.log(err)
}
})
}
gulp.task('sass_compiler', [], () => {
gulp.src(path.src.scss)
.pipe(sass().on('error', sass.logError))
.pipe(rename({
'extname': '.wxss'
}))
.pipe(replace('.scss', '.wxss'))
.pipe(gulp.dest(path[options.env]))
})
gulp.task('component_carrier', [], () => {
gulp.src([path.src.wxml, path.src.json, path.src.js])
.pipe(gulp.dest(path[options.env]))
})
gulp.task('component_cleaner', [], () => {
return del(path[options.env])
})
gulp.task('default', [], () => {
if (options.env === 'dev') {
runBuild(() => {
let watcher = gulp.watch(path.src.all, () => {
runBuild()
})
watcher.on('change', () => {
console.log('changed')
})
})
} else if (options.env === 'production') {
runBuild(() => {
console.log('finish')
})
}
})