forked from tailwindlabs/tailwindcss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
60 lines (50 loc) · 1.91 KB
/
index.js
File metadata and controls
60 lines (50 loc) · 1.91 KB
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
51
52
53
54
55
56
57
58
59
60
import path from 'path'
import _ from 'lodash'
import postcss from 'postcss'
import perfectionist from 'perfectionist'
import registerConfigAsDependency from './lib/registerConfigAsDependency'
import substituteTailwindAtRules from './lib/substituteTailwindAtRules'
import evaluateTailwindFunctions from './lib/evaluateTailwindFunctions'
import substituteVariantsAtRules from './lib/substituteVariantsAtRules'
import substituteResponsiveAtRules from './lib/substituteResponsiveAtRules'
import substituteScreenAtRules from './lib/substituteScreenAtRules'
import substituteClassApplyAtRules from './lib/substituteClassApplyAtRules'
import mergeConfigWithDefaults from './util/mergeConfigWithDefaults'
const plugin = postcss.plugin('tailwind', config => {
const plugins = []
if (!_.isUndefined(config)) {
plugins.push(registerConfigAsDependency(path.resolve(config)))
}
const lazyConfig = () => {
if (_.isUndefined(config)) {
return require('../defaultConfig')()
}
delete require.cache[require.resolve(path.resolve(config))]
return mergeConfigWithDefaults(require(path.resolve(config)), require('../defaultConfig')())
}
return postcss(
...plugins,
...[
substituteTailwindAtRules(lazyConfig),
evaluateTailwindFunctions(lazyConfig),
substituteVariantsAtRules(lazyConfig),
substituteResponsiveAtRules(lazyConfig),
substituteScreenAtRules(lazyConfig),
substituteClassApplyAtRules(lazyConfig),
perfectionist({
cascade: true,
colorShorthand: true,
indentSize: 2,
maxSelectorLength: 1,
maxValueLength: false,
trimLeadingZero: true,
trimTrailingZeros: true,
}),
]
)
})
plugin.defaultConfig = function() {
// prettier-ignore
throw new Error("`require('tailwindcss').defaultConfig()` is no longer a function, access it instead as `require('tailwindcss/defaultConfig')()`.")
}
module.exports = plugin