Optimize rebuilds in long-running processes
This commit is contained in:
parent
d3606b76dc
commit
ef149cfafb
8 changed files with 122 additions and 139 deletions
|
|
@ -16,25 +16,33 @@ import processPlugins from './util/processPlugins'
|
|||
import cloneNodes from './util/cloneNodes'
|
||||
import { issueFlagNotices } from './featureFlags.js'
|
||||
|
||||
import hash from 'object-hash'
|
||||
|
||||
let flagsIssued = null
|
||||
let previousConfig = null
|
||||
let processedPlugins = null
|
||||
let getProcessedPlugins = null
|
||||
|
||||
export default function(getConfig) {
|
||||
return function(css) {
|
||||
const config = getConfig()
|
||||
const configChanged = hash(previousConfig) !== hash(config)
|
||||
previousConfig = config
|
||||
|
||||
if (!flagsIssued || !_.isEqual(flagsIssued, _.pick(config, ['future', 'experimental']))) {
|
||||
flagsIssued = _.pick(config, ['future', 'experimental'])
|
||||
issueFlagNotices(config)
|
||||
}
|
||||
|
||||
const processedPlugins = processPlugins([...corePlugins(config), ...config.plugins], config)
|
||||
|
||||
const getProcessedPlugins = function() {
|
||||
return {
|
||||
...processedPlugins,
|
||||
base: cloneNodes(processedPlugins.base),
|
||||
components: cloneNodes(processedPlugins.components),
|
||||
utilities: cloneNodes(processedPlugins.utilities),
|
||||
if (configChanged) {
|
||||
processedPlugins = processPlugins([...corePlugins(config), ...config.plugins], config)
|
||||
getProcessedPlugins = function() {
|
||||
return {
|
||||
...processedPlugins,
|
||||
base: cloneNodes(processedPlugins.base),
|
||||
components: cloneNodes(processedPlugins.components),
|
||||
utilities: cloneNodes(processedPlugins.utilities),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -45,7 +53,7 @@ export default function(getConfig) {
|
|||
substituteResponsiveAtRules(config),
|
||||
convertLayerAtRulesToControlComments(config),
|
||||
substituteScreenAtRules(config),
|
||||
substituteClassApplyAtRules(config, getProcessedPlugins),
|
||||
substituteClassApplyAtRules(config, getProcessedPlugins, configChanged),
|
||||
applyImportantConfiguration(config),
|
||||
purgeUnusedStyles(config),
|
||||
]).process(css, { from: _.get(css, 'source.input.file') })
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue