增加容错处理,避免程序崩溃

master
yutent 2023-03-23 14:33:20 +08:00
parent c646875fd7
commit 135bced616
3 changed files with 12 additions and 8 deletions

View File

@ -47,14 +47,17 @@ export default function compile(root = '', isProd = false, es) {
{ {
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( try {
/css`([\w\W]*?)`/g, code = Es.transformSync(code, OPTIONS).code
function (m, scss) { } catch (err) {
console.log('compile scss: ', file)
console.error(err)
}
code = code.replace(/css`([\w\W]*?)`/g, 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

View File

@ -24,5 +24,6 @@ export function compileScss(file, mini = true) {
} catch (err) { } catch (err) {
console.log('compile scss: ', file) console.log('compile scss: ', file)
console.error(err) console.error(err)
return ''
} }
} }

View File

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