2018-07-16 08:35:58 -04:00
|
|
|
import _ from 'lodash'
|
2018-06-22 20:52:59 -04:00
|
|
|
import postcss from 'postcss'
|
|
|
|
|
|
|
|
|
|
import substituteTailwindAtRules from './lib/substituteTailwindAtRules'
|
|
|
|
|
import evaluateTailwindFunctions from './lib/evaluateTailwindFunctions'
|
|
|
|
|
import substituteVariantsAtRules from './lib/substituteVariantsAtRules'
|
|
|
|
|
import substituteResponsiveAtRules from './lib/substituteResponsiveAtRules'
|
2020-07-15 09:41:19 -04:00
|
|
|
import convertLayerAtRulesToControlComments from './lib/convertLayerAtRulesToControlComments'
|
2018-06-22 20:52:59 -04:00
|
|
|
import substituteScreenAtRules from './lib/substituteScreenAtRules'
|
|
|
|
|
import substituteClassApplyAtRules from './lib/substituteClassApplyAtRules'
|
2020-08-14 12:23:28 -04:00
|
|
|
import applyImportantConfiguration from './lib/applyImportantConfiguration'
|
2020-04-28 09:51:27 -04:00
|
|
|
import purgeUnusedStyles from './lib/purgeUnusedStyles'
|
2018-07-11 11:45:45 -04:00
|
|
|
|
2019-01-31 19:23:18 -05:00
|
|
|
import corePlugins from './corePlugins'
|
2018-06-22 20:57:40 -04:00
|
|
|
import processPlugins from './util/processPlugins'
|
2020-07-21 10:21:57 -04:00
|
|
|
import cloneNodes from './util/cloneNodes'
|
2020-10-17 21:18:15 -04:00
|
|
|
import { issueFlagNotices } from './featureFlags.js'
|
2020-09-11 10:15:39 -04:00
|
|
|
|
2020-08-19 09:33:03 -04:00
|
|
|
import hash from 'object-hash'
|
2020-10-15 12:37:56 -04:00
|
|
|
import log from './util/log'
|
2020-12-11 15:03:49 +01:00
|
|
|
import { shared } from './util/disposables'
|
2020-08-19 09:33:03 -04:00
|
|
|
|
|
|
|
|
let previousConfig = null
|
|
|
|
|
let processedPlugins = null
|
|
|
|
|
let getProcessedPlugins = null
|
2020-08-18 21:14:10 -04:00
|
|
|
|
2020-10-16 13:30:06 -04:00
|
|
|
export default function (getConfig) {
|
|
|
|
|
return function (css) {
|
2018-07-16 08:37:23 -04:00
|
|
|
const config = getConfig()
|
2020-08-19 09:33:03 -04:00
|
|
|
const configChanged = hash(previousConfig) !== hash(config)
|
|
|
|
|
previousConfig = config
|
2020-08-05 13:59:59 -04:00
|
|
|
|
2020-08-19 10:56:51 -04:00
|
|
|
if (configChanged) {
|
2020-12-11 15:03:49 +01:00
|
|
|
shared.dispose()
|
2020-10-15 12:37:56 -04:00
|
|
|
if (config.target) {
|
|
|
|
|
log.warn([
|
|
|
|
|
'The `target` feature has been removed in Tailwind CSS v2.0.',
|
|
|
|
|
'Please remove this option from your config file to silence this warning.',
|
|
|
|
|
])
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-18 21:14:10 -04:00
|
|
|
issueFlagNotices(config)
|
2020-08-05 13:59:59 -04:00
|
|
|
|
2020-09-11 10:15:39 -04:00
|
|
|
processedPlugins = processPlugins(
|
2020-10-17 21:17:12 -04:00
|
|
|
[...corePlugins(config), ..._.get(config, 'plugins', [])],
|
2020-09-11 10:15:39 -04:00
|
|
|
config
|
|
|
|
|
)
|
|
|
|
|
|
2020-10-16 13:30:06 -04:00
|
|
|
getProcessedPlugins = function () {
|
2020-08-19 09:33:03 -04:00
|
|
|
return {
|
|
|
|
|
...processedPlugins,
|
|
|
|
|
base: cloneNodes(processedPlugins.base),
|
|
|
|
|
components: cloneNodes(processedPlugins.components),
|
|
|
|
|
utilities: cloneNodes(processedPlugins.utilities),
|
|
|
|
|
}
|
2020-07-21 10:21:57 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-16 08:30:57 -04:00
|
|
|
return postcss([
|
2020-07-21 10:21:57 -04:00
|
|
|
substituteTailwindAtRules(config, getProcessedPlugins()),
|
2019-01-22 11:47:48 -05:00
|
|
|
evaluateTailwindFunctions(config),
|
2020-07-21 10:21:57 -04:00
|
|
|
substituteVariantsAtRules(config, getProcessedPlugins()),
|
2018-07-16 08:30:57 -04:00
|
|
|
substituteResponsiveAtRules(config),
|
2020-07-15 09:41:19 -04:00
|
|
|
convertLayerAtRulesToControlComments(config),
|
2018-07-16 08:30:57 -04:00
|
|
|
substituteScreenAtRules(config),
|
2020-08-19 09:33:03 -04:00
|
|
|
substituteClassApplyAtRules(config, getProcessedPlugins, configChanged),
|
2020-08-14 12:23:28 -04:00
|
|
|
applyImportantConfiguration(config),
|
2020-08-19 10:56:51 -04:00
|
|
|
purgeUnusedStyles(config, configChanged),
|
2018-07-16 08:35:58 -04:00
|
|
|
]).process(css, { from: _.get(css, 'source.input.file') })
|
2018-07-16 08:30:57 -04:00
|
|
|
}
|
2018-06-22 20:52:59 -04:00
|
|
|
}
|