How to use the postcss function in postcss

To help you get started, we’ve selected a few postcss examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sebastian-software / postcss-smart-import / test / helpers / compare-fixtures.js View on Github external
export default function(t, name, opts, postcssOpts, warnings)
{
  opts = assign({ path: "test/fixtures/imports" }, opts)
  return postcss(atImport(opts))
    .process(read(name), postcssOpts || {})
    .then((result) => {
      var actual = result.css
      var expected = read(name + ".expected")

      // handy thing: checkout actual in the *.actual.css file
      fs.writeFile("test/fixtures/" + name + ".actual.css", actual, () => {
        t.is(actual, expected)

        if (!warnings)
          warnings = []

        result.warnings().forEach((warning, index) => {
          t.is(
            warning.text,
            warnings[index],
github StarpTech / go-web / app / config / rollup.config.js View on Github external
function cssnext (tagName, css) {
  // A small hack: it passes :scope as :root to PostCSS.
  // This make it easy to use css variables inside tags.
  css = css.replace(/:scope/g, ':root')
  css = postcss([postcssCssnext]).process(css).css
  css = css.replace(/:root/g, ':scope')
  return css
}
github SerkanSipahi / app-decorators / packages / postcss-parse-atrule-events / src / index.js View on Github external
let parse = (styles, options = {}) => {

    styles = escapeAtRuleQueryVars(styles);

    if(typeof styles !== "string"){
        throw new Error('Please styles as string!');
    }

    let container = [];
    // normalize nested css before converting to ast
    let content = postcss([nestedCss({ bubble: POSTCSS_BUBBLES })/*, prefixer*/]).process(styles).content;
    let ast = compiler.parse(content);

    // walk trough classic css selectors
    ast.walkRules(node => push(container, getRuleConfig(node)));

    // walk trough @ action /my/{{foo}}/route.html, @on ...
    ast.walkAtRules(node => push(container, getAtRuleConfig(node)));

    // combine/concat same attachOn´s
    options.optimize ? container = optimize(container) : null;

    // check in which constellation @ allowed
    options.grammarCheck ? grammarCheck(container) : null;

    return container;
};
github ben-eb / midas / src / __tests__ / postcss.js View on Github external
test('should be consumed as a postcss stringifier', t => {
    return postcss().process('h1{}', {stringifier: midas}).then(result => {
        t.deepEqual('<pre class="midas"><code><span class="midas__selector"><span class="midas__tag">h1</span></span><span class="midas__brace">{</span><span class="midas__brace">}</span></code></pre>', result.content);
    });
});
github sebastian-software / postcss-smart-import / test / callback.js View on Github external
test("should have a callback that returns an object containing imported files", (t) =>
  postcss()
    .use(atImport({
      path: "test/fixtures/imports",
      onImport: (files) =>
      {
        t.deepEqual(
          files,
          [
            resolve("test/fixtures/media-import.css"),
            resolve("test/fixtures/imports/media-import-level-2.css"),
            resolve("test/fixtures/imports/media-import-level-3.css")
          ]
        )
      }
    }))
    .process(readFileSync("test/fixtures/media-import.css"), {
      from: "test/fixtures/media-import.css"
github rebem / css / test / lib / index.js View on Github external
it('mods', function() {
            process.env.REBEM_MOD_DELIM = '~~';

            const CustomPlugin = requireUncached('../../lib/');

            assert.strictEqual(
                postcss([ CustomPlugin ]).process(':block(block):mod(mod val){}').css,
                '.block~~mod~~val{}'
            );
        });
github sebastian-software / edge / packages / edge-postcss / __tests__ / core.js View on Github external
export async function compileSameFolder(input) {
  const allOptions = {
    ...options,
    from: "__tests__/fixtures/main.css",
    to: "__tests__/fixtures/main.out.css"
  }

  const result = await postcss(plugins)
    .process(input, allOptions)

  expect(format(result.css)).toMatchSnapshot()
}
github bluedaniel / Kakapo-app / tools / css.js View on Github external
export default async function css() {
  const source = fs.readFileSync('./app/css/downloads.css', 'utf8');
  const output = postcss(postcssPlugins).process(source, {
    from: './app/scripts/styles'
  })
  .catch(err => console.error(err.stack));

  await output.then(data => {
    const minifyOpts = {
      discardComments: { removeAll: true }
    };
    cssnano.process(data.css, minifyOpts).then(minified =>
      fs.outputFile('./build/css/downloads.css', minified.css));
  });
}
github evnbr / bindery / rollup.config.js View on Github external
  processor: css => postcss([
    prefixer('📖-'),
    cssnano(),
  ]).process(css).then(result => result.css),
});