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
|
|
|
|
* @param file <String> 文件路径或scss代码
|
|
|
|
* @param mini <Boolean> 是否压缩
|
|
|
|
*/
|
|
|
|
export function compileScss(file, mini = true) {
|
|
|
|
let style = mini ? 'compressed' : 'expanded'
|
|
|
|
try {
|
|
|
|
if (fs.isfile(file)) {
|
|
|
|
return scss.compile(file, { style, ...OPTIONS }).css.trim()
|
|
|
|
} else {
|
2023-03-15 18:21:34 +08:00
|
|
|
return scss
|
|
|
|
.compileString(file.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)
|
|
|
|
}
|
|
|
|
}
|