forked from tailwindlabs/tailwindcss
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
54 lines (44 loc) · 1.43 KB
/
index.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
51
52
53
54
import path from 'path'
import _ from 'lodash'
import postcss from 'postcss'
import perfectionist from 'perfectionist'
import registerConfigAsDependency from './lib/registerConfigAsDependency'
import processTailwindFeatures from './processTailwindFeatures'
import mergeConfigWithDefaults from './util/mergeConfigWithDefaults'
const plugin = postcss.plugin('tailwind', config => {
const plugins = []
if (!_.isUndefined(config) && !_.isObject(config)) {
plugins.push(registerConfigAsDependency(path.resolve(config)))
}
const getConfig = () => {
if (_.isUndefined(config)) {
return require('../defaultConfig')()
}
if (!_.isObject(config)) {
delete require.cache[require.resolve(path.resolve(config))]
}
return mergeConfigWithDefaults(
_.isObject(config) ? config : require(path.resolve(config)),
require('../defaultConfig')()
)
}
return postcss([
...plugins,
processTailwindFeatures(getConfig),
perfectionist({
cascade: true,
colorShorthand: true,
indentSize: 2,
maxSelectorLength: 1,
maxValueLength: false,
trimLeadingZero: true,
trimTrailingZeros: true,
zeroLengthNoUnit: false,
}),
])
})
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