gregsullivan/_tw

Restore `theme.json` updates to Tailwind configuration during `watch` process

gregsullivan opened this issue · 1 comments

Previous functionality

Updating the theme.json file would trigger Tailwind to rebuild the CSS file with new colour and width properties from the theme.json file.

Current status

Two things seem to have changed:

  1. Opening the theme.json file with require caches its contents, and those contents aren't updated when the file changes.
  2. Tailwind no longer executes the plugin except on startup and when rebuilding the configuration after changes to tailwind.config.js.

Workaround

Right now, the easiest way around this is to terminate the watch process after changing the theme.json file and then to restart it.

Future fixes

There are two options for the caching issue:

  1. Clear the require cache
  2. Open and parse the JSON file without using require

I'm not sure which would be more performant, or if it would make enough of a different to matter.

I want to wait until Tailwind's Oxide compiler is released before putting too much energy into the second issue. One approach that would definitely work would be to watch the theme.json file and then to trigger something equivalent to touch tailwind.config.js. I'd prefer not to add more dependencies, though, and it feels like there should be a better way.

That said, my sense is that Tailwind has consciously been updated to run plugins less often, and that plugins that could produce different values on future runs may have limited options.

Discussed in #78

Originally posted by victorcl November 13, 2023
Hi and thanks for this great wordpress theme starter.

I am having an issue which I haven't been able to sort out. When I make changes to the theme.json, watch gets triggered with "Rebuilding..." but these changes are not available to tailwind.
But if I run "npm run dev" then the changes from theme.json are available to tailwing. But then if I make a change to any other file that triggers "watch" then I loose the theme.json changes again, they reset to the original values.
Any idea¿

Thanks.

I change my mind and fixed this for now:

1fcc039

This will need to be revisited after Oxide launches.