tailwindcss/src/index.js

55 lines
1.4 KiB
JavaScript
Raw Normal View History

import path from 'path'
2017-08-26 14:36:40 -05:00
import _ from 'lodash'
import postcss from 'postcss'
import perfectionist from 'perfectionist'
2017-08-27 18:42:10 -04:00
import registerConfigAsDependency from './lib/registerConfigAsDependency'
import processTailwindFeatures from './processTailwindFeatures'
import resolveConfig from './util/resolveConfig'
const plugin = postcss.plugin('tailwind', config => {
const plugins = []
2018-06-22 21:01:18 -04:00
if (!_.isUndefined(config) && !_.isObject(config)) {
plugins.push(registerConfigAsDependency(path.resolve(config)))
2017-10-26 09:29:23 -04:00
}
2018-07-16 08:37:23 -04:00
const getConfig = () => {
if (_.isUndefined(config)) {
return resolveConfig([require('../defaultConfig')()])
}
2018-06-22 21:01:18 -04:00
if (!_.isObject(config)) {
delete require.cache[require.resolve(path.resolve(config))]
}
return resolveConfig([
2018-06-22 21:01:18 -04:00
_.isObject(config) ? config : require(path.resolve(config)),
require('../defaultConfig')(),
])
}
return postcss([
...plugins,
2018-07-16 08:37:23 -04:00
processTailwindFeatures(getConfig),
perfectionist({
cascade: true,
colorShorthand: true,
indentSize: 2,
maxSelectorLength: 1,
maxValueLength: false,
trimLeadingZero: true,
trimTrailingZeros: true,
zeroLengthNoUnit: false,
}),
])
2017-08-24 19:38:25 -04:00
})
2017-08-28 15:02:50 -05:00
2017-11-17 10:38:40 -05:00
plugin.defaultConfig = function() {
// prettier-ignore
throw new Error("`require('tailwindcss').defaultConfig()` is no longer a function, access it instead as `require('tailwindcss/defaultConfig')()`.")
}
2017-08-28 15:02:50 -05:00
module.exports = plugin