cli/lib/utils.js

26 lines
539 B
JavaScript
Raw Normal View History

2023-03-14 15:39:00 +08:00
import scss from '@bytedo/sass'
import fs from 'iofs'
const OPTIONS = {
indentType: 'space',
indentWidth: 2
}
/**
* 编译scss为css
2023-04-20 13:53:48 +08:00
* @param source <String> scss代码
2023-03-14 15:39:00 +08:00
* @param mini <Boolean> 是否压缩
*/
2023-04-20 13:53:48 +08:00
export function compileScss(source, mini = true) {
2023-03-14 15:39:00 +08:00
let style = mini ? 'compressed' : 'expanded'
try {
2023-04-20 13:53:48 +08:00
return scss
.compileString(source.replace(/@loop/g, '@each'), { style, ...OPTIONS })
.css.trim()
2023-03-14 15:39:00 +08:00
} catch (err) {
console.log('compile scss: ', file)
console.error(err)
2023-03-23 14:33:20 +08:00
return ''
2023-03-14 15:39:00 +08:00
}
}