How to use the purgecss.mergeExtractorSelectors function in purgecss

To help you get started, we’ve selected a few purgecss 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 FullHuman / purgecss / packages / postcss-purgecss / lib / postcss-purgecss.js View on Github external
return async function(s, t) {
    const r = new purgecss.PurgeCSS(),
      o = { ...purgecss.defaultOptions, ...e };
    r.options = o;
    const { content: c, extractors: n } = o,
      u = c.filter(e => "string" == typeof e),
      p = c.filter(e => "object" == typeof e),
      i = await r.extractSelectorsFromFiles(u, n),
      l = r.extractSelectorsFromString(p, n),
      g = purgecss.mergeExtractorSelectors(i, l);
    r.walkThroughCSS(s, g),
      r.options.fontFace && r.removeUnusedFontFaces(),
      r.options.keyframes && r.removeUnusedKeyframes(),
      r.options.rejected &&
        r.selectorsRemoved.size > 0 &&
        (t.messages.push({
          type: "purgecss",
          plugin: "postcss-purgecss",
          text: `purging ${
            r.selectorsRemoved.size
          } selectors:\n        ${Array.from(r.selectorsRemoved)
            .map(e => e.trim())
            .join("\n  ")}`
        }),
        r.selectorsRemoved.clear());
  };
github FullHuman / purgecss / packages / postcss-purgecss / src / index.ts View on Github external
o => typeof o === "string"
    ) as string[];
    const rawFormatContents = content.filter(
      o => typeof o === "object"
    ) as RawContent[];

    const cssFileSelectors = await purgeCSS.extractSelectorsFromFiles(
      fileFormatContents,
      extractors
    );
    const cssRawSelectors = purgeCSS.extractSelectorsFromString(
      rawFormatContents,
      extractors
    );

    const selectors = mergeExtractorSelectors(
      cssFileSelectors,
      cssRawSelectors
    );

    //purge unused selectors
    purgeCSS.walkThroughCSS(root, selectors);

    if (purgeCSS.options.fontFace) purgeCSS.removeUnusedFontFaces();
    if (purgeCSS.options.keyframes) purgeCSS.removeUnusedKeyframes();

    if (purgeCSS.options.rejected && purgeCSS.selectorsRemoved.size > 0) {
      result.messages.push({
        type: "purgecss",
        plugin: "postcss-purgecss",
        text: `purging ${purgeCSS.selectorsRemoved.size} selectors:
        ${Array.from(purgeCSS.selectorsRemoved)
github FullHuman / purgecss / packages / postcss-purgecss / lib / postcss-purgecss.esm.js View on Github external
return async function(r, c) {
    const n = new s(),
      p = { ...o, ...e };
    n.options = p;
    const { content: i, extractors: m } = p,
      a = i.filter(e => "string" == typeof e),
      l = i.filter(e => "object" == typeof e),
      u = await n.extractSelectorsFromFiles(a, m),
      f = n.extractSelectorsFromString(l, m),
      g = t(u, f);
    n.walkThroughCSS(r, g),
      n.options.fontFace && n.removeUnusedFontFaces(),
      n.options.keyframes && n.removeUnusedKeyframes(),
      n.options.rejected &&
        n.selectorsRemoved.size > 0 &&
        (c.messages.push({
          type: "purgecss",
          plugin: "postcss-purgecss",
          text: `purging ${
            n.selectorsRemoved.size
          } selectors:\n        ${Array.from(n.selectorsRemoved)
            .map(e => e.trim())
            .join("\n  ")}`
        }),
        n.selectorsRemoved.clear());
  };

purgecss

Remove unused css selectors

MIT
Latest version published 1 month ago

Package Health Score

95 / 100
Full package analysis