postcss 是功能核心库。它能够读取插件并转换代码,另外还内置了许多操作 AST
的方法。
基础的使用形式如下:
js
const postcss = require('postcss')
postcss(plugins)
.process(css, { from, to })
.then(result => {
console.log(result.css)
})
关于 postcss
实例上挂载的所有方法可见源码:
js
postcss.stringify = stringify
postcss.parse = parse
postcss.fromJSON = fromJSON
postcss.list = list
postcss.comment = defaults => new Comment(defaults)
postcss.atRule = defaults => new AtRule(defaults)
postcss.decl = defaults => new Declaration(defaults)
postcss.rule = defaults => new Rule(defaults)
postcss.root = defaults => new Root(defaults)
postcss.document = defaults => new Document(defaults)
postcss.CssSyntaxError = CssSyntaxError
postcss.Declaration = Declaration
postcss.Container = Container
postcss.Processor = Processor
postcss.Document = Document
postcss.Comment = Comment
postcss.Warning = Warning
postcss.AtRule = AtRule
postcss.Result = Result
postcss.Input = Input
postcss.Rule = Rule
postcss.Root = Root
postcss.Node = Node
关于每一个方法的具体使用和介绍,可以参考官网。