2017-10-15 13:52:51 -04:00
|
|
|
import path from 'path'
|
|
|
|
|
|
2017-08-26 14:36:40 -05:00
|
|
|
import _ from 'lodash'
|
|
|
|
|
import postcss from 'postcss'
|
2018-01-18 22:58:08 -05:00
|
|
|
import perfectionist from 'perfectionist'
|
2017-08-27 18:42:10 -04:00
|
|
|
|
2017-11-03 09:54:15 -04:00
|
|
|
import registerConfigAsDependency from './lib/registerConfigAsDependency'
|
2018-06-22 20:52:59 -04:00
|
|
|
import processTailwindFeatures from './processTailwindFeatures'
|
2019-02-05 20:36:54 -05:00
|
|
|
import resolveConfig from './util/resolveConfig'
|
2017-11-22 13:26:18 -05:00
|
|
|
|
2017-11-04 00:35:59 -05:00
|
|
|
const plugin = postcss.plugin('tailwind', config => {
|
2017-11-03 09:54:15 -04:00
|
|
|
const plugins = []
|
|
|
|
|
|
2018-06-22 21:01:18 -04:00
|
|
|
if (!_.isUndefined(config) && !_.isObject(config)) {
|
2017-11-03 09:54:15 -04:00
|
|
|
plugins.push(registerConfigAsDependency(path.resolve(config)))
|
2017-10-26 09:29:23 -04:00
|
|
|
}
|
|
|
|
|
|
2018-07-16 08:37:23 -04:00
|
|
|
const getConfig = () => {
|
2017-11-03 09:54:15 -04:00
|
|
|
if (_.isUndefined(config)) {
|
2019-02-05 20:36:54 -05:00
|
|
|
return resolveConfig([require('../defaultConfig')()])
|
2017-11-03 09:54:15 -04:00
|
|
|
}
|
|
|
|
|
|
2018-06-22 21:01:18 -04:00
|
|
|
if (!_.isObject(config)) {
|
|
|
|
|
delete require.cache[require.resolve(path.resolve(config))]
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-05 20:36:54 -05:00
|
|
|
return resolveConfig([
|
2018-06-22 21:01:18 -04:00
|
|
|
_.isObject(config) ? config : require(path.resolve(config)),
|
2019-02-05 20:36:54 -05:00
|
|
|
require('../defaultConfig')(),
|
|
|
|
|
])
|
2017-10-15 13:52:51 -04:00
|
|
|
}
|
|
|
|
|
|
2018-06-22 20:52:59 -04:00
|
|
|
return postcss([
|
2017-11-04 00:35:59 -05:00
|
|
|
...plugins,
|
2018-07-16 08:37:23 -04:00
|
|
|
processTailwindFeatures(getConfig),
|
2018-06-22 20:52:59 -04:00
|
|
|
perfectionist({
|
|
|
|
|
cascade: true,
|
|
|
|
|
colorShorthand: true,
|
|
|
|
|
indentSize: 2,
|
|
|
|
|
maxSelectorLength: 1,
|
|
|
|
|
maxValueLength: false,
|
|
|
|
|
trimLeadingZero: true,
|
|
|
|
|
trimTrailingZeros: true,
|
2018-08-14 13:37:08 -04:00
|
|
|
zeroLengthNoUnit: false,
|
2018-06-22 20:52:59 -04:00
|
|
|
}),
|
|
|
|
|
])
|
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
|
2017-11-17 10:37:57 -05:00
|
|
|
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
|