-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathgulpfile.js
128 lines (113 loc) · 3.14 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
const gulp = require('gulp')
const clean = require('gulp-clean')
const changed = require('gulp-changed')
const change = require('gulp-change')
const config = require('./gulp.config')
const sourcemaps = require('gulp-sourcemaps')
const { handleSource } = require('@dcasia/mini-program-tailwind-webpack-plugin/dist/universal-handler')
const { Processor } = require('windicss/lib')
const { HTMLParser } = require('windicss/utils/parser')
const through2 = require('through2')
const fs = require('fs')
const windiConfig = require('./windi.config.js')
const outDir = config.outDir
const styleSrc = config.style.src
const templateSrc = config.template.src
const otherSrc = config.other.src
const processor = new Processor(windiConfig)
gulp.task('handle:style', () =>
gulp.src(
styleSrc,
{
since: gulp.lastRun('handle:style')
}
)
.pipe(sourcemaps.init())
.pipe(change(content => {
return handleSource('style', content, {enableRpx: true})
}))
.pipe(sourcemaps.write())
.pipe(gulp.dest(outDir))
)
gulp.task('handle:template',
gulp.series(
() => gulp.src(templateSrc)
.pipe(changed(outDir))
.pipe(change((content) => {
return handleSource('template', content)
}))
.pipe(gulp.dest(outDir)),
() => gulp.src(templateSrc)
.pipe(through2.obj(function(file, enc, cb) {
let result = ''
if (file.isBuffer()) {
const wxmlContent = file.contents.toString()
const content = new HTMLParser(wxmlContent)
.parseClasses()
.map(i => i.result)
.join(' ')
const interpretedSheet = processor.interpret(content, true).styleSheet
const MINIFY = true
const styles = interpretedSheet.build(MINIFY)
result = handleSource('style', styles, {enableRpx: true})
}
cb(null, result)
}))
.pipe(fs.createWriteStream('./dist/windi.wxss', {'flags': 'a'}))
)
)
gulp.task('handle:other', () =>
gulp.src(otherSrc)
.pipe(changed(outDir))
.pipe(gulp.dest(outDir))
)
gulp.task('watch:style', () => {
gulp.watch(
styleSrc,
gulp.series('handle:style')
)
})
gulp.task('watch:template', () => {
gulp.watch(
templateSrc,
gulp.series('handle:template')
)
})
gulp.task('watch:other', () => {
gulp.watch(
otherSrc,
gulp.series('handle:other')
)
})
gulp.task(
'watch',
gulp.parallel(
'watch:style',
'watch:template',
'watch:other'
)
)
gulp.task('clean', () =>
gulp.src(
[
'dist',
'./src/windi.wxss'
],
{
allowEmpty: true
}
)
.pipe(clean())
)
gulp.task(
'default',
gulp.series(
'clean',
gulp.parallel(
'handle:style',
'handle:template',
),
'handle:other',
'watch'
)
)