Push CSS-based theme resolution inside getTailwindConfig

This commit is contained in:
Jordan Pittman 2023-06-15 12:13:05 -04:00 • committed by Robin Malfait
parent d88fd1e6e7
commit ed7c448441
No known key found for this signature in database
GPG key ID: 92F53D68B9041AFE
3 changed files with 9 additions and 7 deletions

View file

@ -5,8 +5,9 @@
*/
export class CssBasedConfig {
/** @type {*} */
config = {};
constructor() {
this.config = {}
}
/**
* Find and convert the `:theme` rule to a configuration object

View file

@ -12,6 +12,7 @@ import { validateConfig } from '../util/validateConfig.js'
import { parseCandidateFiles, resolvedChangedContent } from './content.js'
import { loadConfig } from '../lib/load-config'
import getModuleDependencies from './getModuleDependencies'
import { CssBasedConfig } from './parseCssConfig.js'
let configPathCache = new LRU({ maxSize: 100 })
@ -80,9 +81,12 @@ function getTailwindConfig(configOrPath, cssThemeValues = {}) {
// Retrieve an existing context from cache if possible (since contexts are unique per
// source path), or set up a new one (including setting up watchers and registering
// plugins) then return it
export default function setupTrackingContext(configOrPath, cssThemeValues = {}) {
export default function setupTrackingContext(configOrPath) {
return ({ tailwindDirectives, registerDependency }) => {
return (root, result) => {
// Parse any CSS-based config values from `:theme` rules
let cssThemeValues = new CssBasedConfig().parse(root)
let [tailwindConfig, userConfigPath, tailwindConfigHash, configDependencies] =
getTailwindConfig(configOrPath, cssThemeValues)

View file

@ -24,10 +24,7 @@ module.exports = function tailwindcss(configOrPath) {
// path for the file being processed
configOrPath = findAtConfigPath(root, result) ?? configOrPath
// Parse any CSS-based config values from `:theme` rules
let themeValues = new CssBasedConfig().parse(root)
let context = setupTrackingContext(configOrPath, themeValues)
let context = setupTrackingContext(configOrPath)
if (root.type === 'document') {
let roots = root.nodes.filter((node) => node.type === 'root')