Push CSS-based theme resolution inside getTailwindConfig
This commit is contained in:
parent
d88fd1e6e7
commit
ed7c448441
3 changed files with 9 additions and 7 deletions
|
|
@ -5,8 +5,9 @@
|
|||
*/
|
||||
|
||||
export class CssBasedConfig {
|
||||
/** @type {*} */
|
||||
config = {};
|
||||
constructor() {
|
||||
this.config = {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find and convert the `:theme` rule to a configuration object
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue