Skip to content

Commit 578dace

Browse files
committed
update: modify build scripts
1 parent 4f23c8b commit 578dace

File tree

3 files changed

+55
-5
lines changed

3 files changed

+55
-5
lines changed

tools/build.js

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,16 @@ function copy(copyFileList) {
167167
.pipe(gulp.dest(distPath))
168168
}
169169

170+
/**
171+
* 拷贝 weui-wxss 中的样式文件
172+
*/
173+
function copyWeuiWxss() {
174+
return gulp.src(config.copyWeuiWxss, {cwd: srcPath, base: srcPath})
175+
.pipe(_.dealWithWeuiWxss())
176+
.pipe(_.logger())
177+
.pipe(gulp.dest(distPath))
178+
}
179+
170180
/**
171181
* 安装依赖包
172182
*/
@@ -371,6 +381,14 @@ class BuildTask {
371381
return done()
372382
}))
373383

384+
/**
385+
* 拷贝 weui-wxss 到目标目录
386+
*/
387+
gulp.task(`${id}-copy-weui-wxss`, done => {
388+
if (config.copyWeuiWxss && Array.isArray(config.copyWeuiWxss)) return copyWeuiWxss()
389+
return done ()
390+
})
391+
374392
/**
375393
* 监听 json 变化
376394
*/
@@ -424,6 +442,19 @@ class BuildTask {
424442
.on('unlink', watchCallback)
425443
})
426444

445+
/**
446+
* 监听 weui-wxss 变化
447+
*/
448+
gulp.task(`${id}-watch-copy-weui-wxss`, () => {
449+
const copyWeuiWxssList = config.copyWeuiWxss || []
450+
const watchCallback = filePath => copyWeuiWxss([filePath])
451+
452+
return gulp.watch(copyWeuiWxssList, {cwd: srcPath, base: srcPath})
453+
.on('change', watchCallback)
454+
.on('add', watchCallback)
455+
.on('unlink', watchCallback)
456+
})
457+
427458
/**
428459
* 监听 demo 变化
429460
*/
@@ -448,9 +479,9 @@ class BuildTask {
448479
* 构建相关任务
449480
*/
450481
// gulp.task(`${id}-build`, gulp.series(`${id}-clean-dist`, `${id}-component-check`, gulp.parallel(`${id}-component-less`)))
451-
gulp.task(`${id}-build`, gulp.series(`${id}-clean-dist`, `${id}-component-check`, gulp.parallel(`${id}-component-wxml`, `${id}-component-js`, `${id}-component-less`, `${id}-component-wxss`, `${id}-component-json`, `${id}-copy`, `${id}-package-json`)))
482+
gulp.task(`${id}-build`, gulp.series(`${id}-clean-dist`, `${id}-component-check`, gulp.parallel(`${id}-component-wxml`, `${id}-component-js`, `${id}-component-less`, `${id}-component-wxss`, `${id}-component-json`, `${id}-copy`, `${id}-copy-weui-wxss`, `${id}-package-json`)))
452483

453-
gulp.task(`${id}-watch`, gulp.series(`${id}-build`, `${id}-demo`, `${id}-install`, gulp.parallel(`${id}-watch-wxml`, `${id}-watch-wxss`, `${id}-watch-json`, `${id}-watch-copy`, `${id}-watch-install`, `${id}-watch-demo`, `${id}-watch-less`, `${id}-watch-ts`)))
484+
gulp.task(`${id}-watch`, gulp.series(`${id}-build`, `${id}-demo`, `${id}-install`, gulp.parallel(`${id}-watch-wxml`, `${id}-watch-wxss`, `${id}-watch-json`, `${id}-watch-copy`, `${id}-watch-copy-weui-wxss`, `${id}-watch-install`, `${id}-watch-demo`, `${id}-watch-less`, `${id}-watch-ts`)))
454485

455486
gulp.task(`${id}-dev`, gulp.series(`${id}-build`, `${id}-demo`, `${id}-install`))
456487

tools/config.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,10 @@ module.exports = {
6262
assetFilter: assetFilename => assetFilename.endsWith('.js')
6363
}
6464
},
65-
ignore: ['!./weui-wxss/**/*'], // 要忽
66-
copyIgnore: ['!./weui-wxss/node_modules/**/*', '!./weui-wxss/src/**/*', '!./weui-wxss/dist/example/**/*', '!./weui-wxss/dist/app.wxss', '!./weui-wxss/dist/style/base/**/*', '!./weui-wxss/dist/style/widget/**/*'], // 要忽略的目录/文件
65+
ignore: ['!./weui-wxss/**/*'], // 要忽略的目录/文件
66+
copyIgnore: ['!./weui-wxss/**/*'], // 要忽略的目录/文件
6767
copy: {
68-
src: ['./static/**/*', './**/*.wxss', './**/*.wxs', './weui-wxss/dist/style/weui.wxss']
68+
src: ['./static/**/*', './**/*.wxss', './**/*.wxs', ]
6969
}, // 将会复制到目标目录
70+
copyWeuiWxss: ['./weui-wxss/dist/style/weui.wxss', './weui-wxss/dist/style/icon/weui-icon.wxss']
7071
}

tools/utils.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,23 @@ function getId() {
196196
return ++seed
197197
}
198198

199+
/**
200+
* weui-wxss 处理插件
201+
*/
202+
function dealWithWeuiWxss() {
203+
return through.obj(function (file, enc, cb) {
204+
if (path.extname(file.path) === '.wxss') {}
205+
const action = 'copy'
206+
const type = path.extname(file.path).slice(1).toLowerCase()
207+
208+
// eslint-disable-next-line no-console
209+
console.log(`[${format(new Date(), 'yyyy-MM-dd HH:mm:ss').grey}] [${action.green} ${type.green}] ${'=>'.cyan} ${file.path}`)
210+
211+
this.push(file)
212+
cb()
213+
})
214+
}
215+
199216
module.exports = {
200217
wrap,
201218
transformPath,
@@ -210,4 +227,5 @@ module.exports = {
210227
compareArray,
211228
merge,
212229
getId,
230+
dealWithWeuiWxss,
213231
}

0 commit comments

Comments
 (0)