修复编译顺序

master
yutent 2023-04-20 13:53:48 +08:00
parent 10fe226d0a
commit 661542fa41
3 changed files with 10 additions and 15 deletions

View File

@ -53,16 +53,15 @@ export default function compile(root = '', isProd = false, es) {
let code = fs.cat(filePath).toString()
console.log('编译 %s ...', blue(file))
try {
code = code.replace(/css`([\w\W]*?)`/g, function (m, scss) {
scss = compileScss(scss)
return `css\`${scss}\``
})
code = Es.transformSync(code, OPTIONS).code
} catch (err) {
console.log('compile scss: ', file)
console.error(err)
}
code = code.replace(/css`([\w\W]*?)`/g, function (m, scss) {
scss = compileScss(scss)
return `css\`${scss}\``
})
fs.echo(code, target)
}
break

View File

@ -8,19 +8,15 @@ const OPTIONS = {
/**
* 编译scss为css
* @param file <String> 文件路径或scss代码
* @param source <String> scss代码
* @param mini <Boolean> 是否压缩
*/
export function compileScss(file, mini = true) {
export function compileScss(source, mini = true) {
let style = mini ? 'compressed' : 'expanded'
try {
if (fs.isfile(file)) {
return scss.compile(file, { style, ...OPTIONS }).css.trim()
} else {
return scss
.compileString(file.replace(/@loop/g, '@each'), { style, ...OPTIONS })
.css.trim()
}
return scss
.compileString(source.replace(/@loop/g, '@each'), { style, ...OPTIONS })
.css.trim()
} catch (err) {
console.log('compile scss: ', file)
console.error(err)

View File

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