summaryrefslogtreecommitdiff
path: root/src/stylesheets/lib/postcss-minify-selectors.js
blob: 6571c0ce8ce06cadc65e65f83718f928ce61cc14 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
'use strict'

const selectorParser = require('postcss-selector-parser')

/**
 * Replaces the official postcss-minify-selectors plugin with a simpler implementation.
 *
 * The official plugin sorts the selectors and mangles pseudo-elements.
 * This simpler plugin only removes space characters and unnecessary quotes.
 */
module.exports = (opts) => {
  return {
    postcssPlugin: 'postcss-minify-selectors',
    Rule (rule) {
      rule.selector = selectorParser((selectors) => {
        selectors.walkAttributes((attr) => {
          if (attr.value) attr.raws.value = attr.getQuotedValue({ smart: true })
        })
      }).processSync(rule.selector, { lossless: false })
    },
  }
}

module.exports.postcss = true