调整开发模式

master
yutent 2023-03-15 11:20:53 +08:00
parent ad1bf86ff3
commit d49e92bf63
2 changed files with 30 additions and 33 deletions

View File

@ -27,46 +27,43 @@ export default function compile(root = '', isProd = false, es) {
chokidar chokidar
.watch(SOURCE_DIR) .watch(SOURCE_DIR)
.on('all', (act, filePath) => { .on('all', (act, filePath) => {
if (isProd || ready) { let file = filePath.slice(SOURCE_DIR.length)
let file = filePath.slice(SOURCE_DIR.length) let target = join(DIST_DIR, file)
let target = join(DIST_DIR, file)
if (act === 'add' || act === 'change') { if (act === 'add' || act === 'change') {
let ext = file.slice(file.lastIndexOf('.') + 1) let ext = file.slice(file.lastIndexOf('.') + 1)
switch (ext) { switch (ext) {
case 'css': case 'css':
case 'jpg': case 'jpg':
case 'png': case 'png':
case 'svg': case 'svg':
case 'json': case 'json':
case 'gif': case 'gif':
case 'webp': case 'webp':
console.log('复制 %s ...', blue(file)) console.log('复制 %s ...', blue(file))
fs.cp(filePath, target) fs.cp(filePath, target)
break break
case 'js': case 'js':
{ {
let code = fs.cat(filePath).toString() let code = fs.cat(filePath).toString()
console.log('编译 %s ...', blue(file)) console.log('编译 %s ...', blue(file))
code = Es.transformSync(code, OPTIONS).code.replace( code = Es.transformSync(code, OPTIONS).code.replace(
/css`([\w\W]*?)`/g, /css`([\w\W]*?)`/g,
function (m, scss) { function (m, scss) {
scss = compileScss(scss) scss = compileScss(scss)
return `css\`${scss}\`` return `css\`${scss}\``
} }
) )
fs.echo(code, target) fs.echo(code, target)
} }
break break
}
} }
} }
}) })
.on('ready', () => { .on('ready', () => {
ready = true
if (isProd) { if (isProd) {
process.exit() process.exit()
} }

View File

@ -1,7 +1,7 @@
{ {
"name": "@bd/wcui-cli", "name": "@bd/wcui-cli",
"type": "module", "type": "module",
"version": "1.0.0", "version": "1.0.1",
"bin": { "bin": {
"wcui-cli": "index.js" "wcui-cli": "index.js"
}, },