Skip to content
This repository has been archived by the owner on Apr 6, 2021. It is now read-only.

feat: support caching context with options as object #12

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

pi0
Copy link

@pi0 pi0 commented Mar 13, 2021

This PR allows external tooling like nuxt to provide a generated hash in options (passed as object) to reuse context

image

@@ -146,6 +146,7 @@ function resolveConfigPath(pathOrConfig) {
}

let configPathCache = new LRU({ maxSize: 100 })
let lastTailwindConfigHash = null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's safe to store this globally, there can be multiple Tailwind builds happening at the same time in one process (like someone compiling 3 Tailwind configs in one webpack config) so you can never assume there is only one Tailwind config file unfortunately. This probably needs to be scoped by CSS file that triggered the build

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about exposing a key to specify a source?

The default value would be the path and shall be specified as well has hash for cache optimisation.
This mostly improve the programmatic usage and portability of Tailwind JIT.

Copy link
Author

@pi0 pi0 Mar 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, it is the hash of tailwind config object, not file and regardless contextMap is already in the shared state keyed by sourcePath. But I see your point. I guess then we can use cacheGroup key that differs for each build and if does not exists not caching object.

Copy link
Author

@pi0 pi0 Mar 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adamwathan Last changes are using separate _cacheKey and _cacheValue for object config. With multi config case, one can use different key.

Caching behavior is opt-in and we can mention this in the docs or just left for advanced usage

@pi0 pi0 force-pushed the feat/options-cache branch from 798d394 to a896c60 Compare March 13, 2021 17:40
Base automatically changed from master to main March 17, 2021 10:27
@adamwathan adamwathan force-pushed the main branch 2 times, most recently from f79559e to 989bb37 Compare March 17, 2021 18:51
@adamwathan
Copy link
Member

Still planning to look at this, sorry for the delay! I definitely think it makes perfect sense that we would support providing the hash from the outside for people using objects instead of files as a perf optimization 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants