/ tailwindcss Public
Allow resolving content paths relative to the config file #9396
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge.
Right now we resolve content paths relative the the current working directory ("CWD"). If you run the CLI from a different location than the current working directory you can get unexpected results.
As an example, let's say that your config says that your content files live under
./src/components/**.js. If you run Tailwind CSS using
npx tailwindcss build …from inside the
src/directory then Tailwind will complain about not being able to find any content paths. This doesn't make much sense because, to the user, the content is relative to the "project root" — which is almost always where their config file is.
So, we've added an option
content.relativethat lets you specify this behavior explicitly:
This will let you run Tailwind CSS from anywhere and it will resolve the file paths relative the location of the config file. If you do NOT use a config file (because you're passing an object, because you're using Nuxt with it's Tailwind CSS plugin, or some other third party solution) then the paths are resolved relative to the current working directory.
This is a change we intend to make the default behavior in the future for v4 — as such we've added a flag
future.relativeContentPathsByDefaultthat enables this behavior by default. This allows you to keep using the
arraysyntax for content paths instead of needing the object: