Skip to content

Commit 51c5263

Browse files
committed
improvement #2: skip work, when generated AST is the same
Currently incremental rebuilds are additive, which means that we are not keeping track if we should remove CSS again in development. We can exploit this information, because now we can quickly check the amoutn of generated AST nodes. - If they are the same then nothing new is generated — this means that we can re-use the previous compiled CSS. We don't even have to re-print the AST because we already did do that work in the past. - If there are more AST nodes, something new is generated — this means that we should update the `@tailwind utilities` rule and re-print the CSS. We can store the result for future incremental rebuilds.
1 parent 41fe042 commit 51c5263

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

packages/tailwindcss/src/index.ts

+8
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,16 @@ export function compile(
195195
}
196196

197197
if (tailwindUtilitiesNode) {
198+
let previousAstNodeCount = designSystem.getAstNodeSize()
198199
let newNodes = compileCandidates(allValidCandidates, designSystem).astNodes
199200

201+
// If no new ast nodes were generated, then we can return the original
202+
// CSS. This currently assumes that we only add new ast nodes and never
203+
// remove any.
204+
if (previousAstNodeCount === designSystem.getAstNodeSize()) {
205+
return compiledCss
206+
}
207+
200208
tailwindUtilitiesNode.nodes = newNodes
201209
compiledCss = toCss(ast)
202210
}

0 commit comments

Comments
 (0)