Skip to main content
Module

x/bundler/deps.ts>postcss.Result

A Bundler with the web in mind.
Latest
class postcss.Result
Re-export
import { postcss } from "https://deno.land/x/bundler@0.9.0/deps.ts";
const { Result } = postcss;

Provides the result of the PostCSS transformations.

A Result instance is returned by LazyResult#then or Root#toResult methods.

postcss([autoprefixer]).process(css).then(result => {
 console.log(result.css)
})
const result2 = postcss.parse(css).toResult()

Constructors

new
Result(
processor: Processor,
root: Root | Document,
opts: ResultOptions,
)

Properties

readonly
content: string

An alias for the Result#css property. Use it with syntaxes that generate non-CSS output.

result.css === result.content
css: string

A CSS string representing of Result#root.

postcss.parse('a{}').toResult().css //=> "a{}"

Last runned PostCSS plugin.

An instance of SourceMapGenerator class from the source-map library, representing changes to the Result#root instance.

result.map.toJSON() //=> { version: 3, file: 'a.css', … }
if (result.map) {
  fs.writeFileSync(result.opts.to + '.map', result.map.toString())
}
messages: Message[]

Contains messages from plugins (e.g., warnings or custom messages). Each message should have type and plugin properties.

AtRule: {
  import: (atRule, { result }) {
    const importedFile = parseImport(atRule)
    result.messages.push({
      type: 'dependency',
      plugin: 'postcss-import',
      file: importedFile,
      parent: result.opts.from
    })
  }
}
opts: ResultOptions

Options from the Processor#process or Root#toResult call that produced this Result instance.]

root.toResult(opts).opts === opts
processor: Processor

The Processor instance used for this transformation.

for (const plugin of result.processor.plugins) {
  if (plugin.postcssPlugin === 'postcss-bad') {
    throw 'postcss-good is incompatible with postcss-bad'
  }
})
root: Root | Document

Root node after all transformations.

root.toResult().root === root

Methods

toString(): string

Returns for Result#css content.

result + '' === result.css
warn(message: string, options?: WarningOptions): Warning

Creates an instance of Warning and adds it to Result#messages.

if (decl.important) {
  result.warn('Avoid !important', { node: decl, word: '!important' })
}

Returns warnings from plugins. Filters Warning instances from Result#messages.

result.warnings().forEach(warn => {
  console.warn(warn.toString())
})