mirror of
https://github.com/tailwindlabs/tailwindcss.git
synced 2025-12-08 21:36:08 +00:00
55 lines
1.4 KiB
JavaScript
55 lines
1.4 KiB
JavaScript
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
|