forked from vitejs/vite
/
postcss.config.js
50 lines (46 loc) · 1.24 KB
/
postcss.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
module.exports = {
plugins: [require('postcss-nested'), testDirDep, testSourceInput]
}
const fs = require('fs')
const glob = require('fast-glob')
const path = require('path')
const { normalizePath } = require('vite')
/**
* A plugin for testing the `dir-dependency` message handling.
*/
function testDirDep() {
return {
postcssPlugin: 'dir-dep',
AtRule(atRule, { result, Comment }) {
if (atRule.name === 'test') {
const pattern = normalizePath(
path.resolve(path.dirname(result.opts.from), './glob-dep/*.css')
)
const files = glob.sync(pattern)
const text = files.map((f) => fs.readFileSync(f, 'utf-8')).join('\n')
atRule.parent.insertAfter(atRule, text)
atRule.remove()
result.messages.push({
type: 'dir-dependency',
plugin: 'dir-dep',
dir: './glob-dep',
glob: '*.css',
parent: result.opts.from
})
}
}
}
}
testDirDep.postcss = true
function testSourceInput() {
return {
postcssPlugin: 'source-input',
AtRule(atRule) {
if (atRule.name === 'source-input') {
atRule.after(`/* ${atRule.source.input.from} */`)
atRule.remove()
}
}
}
}
testSourceInput.postcss = true