Golang:使用wellington/go-libsass对CSS进行预处理

wellington/go-libsass是一个用于预处理CSS文件的库,采用 Go封装,100% 与 Sass 兼容的 libsass 项目

不过需要依赖libsass,现在已经过时了,可以考虑使用dart-sass

文档

安装

bash 复制代码
go get github.com/wellington/go-libsass

代码示例

go 复制代码
package main

import (
    "os"

    "github.com/wellington/go-libsass"
)

func main() {
    // 指定输入
    input, _ := os.Open("style.scss")
    defer input.Close()

    // 指定输出
    output, _ := os.Create("out.css")
    defer output.Close()

    // 处理
    comp, _ := libsass.New(output, input)

    // 设置选项
    comp.Option(libsass.OutputStyle(libsass.EXPANDED_STYLE))

    // 运行处理
    comp.Run()
}

输入 style.scss

css 复制代码
div {
  p {
    color: black;
  }
}

输出 out.css

css 复制代码
div p {
  color: black;
}
相关推荐
喵了几个咪1 天前
GoWind CMS 拆解:在 Go 里给 TipTap 搭一套 Yjs 协同后端
开发语言·后端·golang
l1t1 天前
测试用go语言执行脚本把数据保存到SQLite数据库
数据库·golang·sqlite
燕落南枝1 天前
CSS 表单选择器与伪元素选择器详解
前端·css
Agent世界1 天前
千问Go上线我的应用:一句话生成可部署 AI 软件的技术拆解
开发语言·人工智能·golang·ai智能体
小熊吃保安1 天前
Windows也能用 Apple Watch 解锁
windows·rust·开源
念何架构之路1 天前
Go reflect包值操作 Value 的读写、可设置性与 interface 布局
开发语言·后端·golang
紧跟先前的步伐2 天前
Go AI Agent 实战 18|Tool Calling 的基本原理与完整执行流程
前端·数据库·人工智能·ai·golang·1024程序员节
紧跟先前的步伐2 天前
Go AI Agent 实战 17|模型适配层设计:让模型可替换
开发语言·人工智能·后端·ai·golang
l1t2 天前
DeepSeek辅助编写连接sqlite的CLI
数据库·golang·sqlite
计算机就业还在扩大2 天前
第2期-cmp.Ordered+类型推断+刻意未支持的特性
后端·面试·golang