How to use the parse function from postcss

Find comprehensive JavaScript postcss.parse code examples handpicked from public code repositorys.

10
11
12
13
14
15
16
17
18
19

const combined = (
  await Promise.all(files.map(async (file) => await fs.promises.readFile(file, 'utf8')))
).join('');

const astRoot = postcss.parse(combined);

const lookup = {};
astRoot.walkDecls(/^--g/, ({ prop, value }) => {
  if (lookup[prop] && lookup[prop] !== value) {
fork icon340
star icon0
watch icon62

170
171
172
173
174
175
176
177
178
179

#### 开始编写插件
在你的插件`postcss-plugin-demo/index.js`里`options = options || {}`下添加:
```
/* 插入初始化html, body属性 */
const base = postcss.parse(`html, body, ul{
        margin: 0;
        padding: 0;
}`)
css.prepend(base)
fork icon25
star icon70
watch icon12

288
289
290
291
292
293
294
295
296
297
298
 * @param {String} stylesheet
 * @returns {css.Stylesheet} ast
 */


function parseStylesheet(stylesheet) {
  return postcss.parse(stylesheet);
}
/**
 * Serialize a postcss Stylesheet to a String of CSS.
 * @private
fork icon0
star icon0
watch icon1

+ 2 other calls in file

51
52
53
54
55
56
57
58
59
60
}

/**
 * Parse string into declaration property and value
 */
parse(str) {
  let parts = str.split(':')
  let prop = parts[0]
  let value = parts[1]
  if (!value) value = ''
fork icon0
star icon0
watch icon0

71
72
73
74
75
76
77
78
79
Supports.prototype.virtual = function virtual(str) {
    var _parse = this.parse(str),
        prop = _parse[0],
        value = _parse[1];

    var rule = postcss.parse('a{}').first;
    rule.append({ prop: prop, value: value, raws: { before: '' } });
    return rule;
};
fork icon0
star icon0
watch icon0

21
22
23
24
25
26
27
28
29
  }

  return value;
}

var css = postcss.parse(fs.readFileSync(input));

css.eachDecl(function(decl) {
  if (!decl.value) return;
fork icon0
star icon0
watch icon0

110
111
112
113
114
115
116
117
118
119
  }

  Object.keys(group).forEach(key => {
    addUtilities({
      [`.${prefix}-${key}`]: postcssJs.objectify(
        postcss.parse(`${property}: ${group[key]}`)
      )
    });
  });
});
fork icon0
star icon0
watch icon0