Inject @config "..." when a tailwind.config.{js,ts,...} is detected#14635
Conversation
efe9ac4 to
faed6a8
Compare
f5978b6 to
b406485
Compare
1b2705f to
bc60358
Compare
b406485 to
7a39ad7
Compare
bc60358 to
15bea44
Compare
088e23f to
bfcbcb5
Compare
cf0be89 to
f1513ab
Compare
philipp-spiess
left a comment
There was a problem hiding this comment.
Good stuff! Some thoughts on how we can reuse this for the CSS we generate from the JS config too. For the relative path rewrite: If you orient yourself on the other places where we do that, it should be good 👍
| // Inject the `@config` in a sensible place | ||
| // 1. Above the first `@theme` | ||
| // 2. Below the last `@import` | ||
| // 3. At the top of the file |
There was a problem hiding this comment.
This is going to be the place for adding the CSS config if we can migrate the JS config. Maybe we can make the "what is injected" here dynamic so we can decide in the JS config migrator what we need in the css?
There was a problem hiding this comment.
Yep I think once this PR is merged that we can abstract this to a function if we want. Not sure if that's necessary for this PR yet.
There might be some additional logic where we might want to control the order of @config, @theme, injected @variants and so on.
There was a problem hiding this comment.
Haha yep I would need it right away, let's pair on this afterwards 👍
15bea44 to
589d0e8
Compare
d242cca to
baa6ffb
Compare
|
|
||
| --- ./src/input.css --- | ||
| @import 'tailwindcss'; | ||
| @config "../tailwind.config.js";" |
There was a problem hiding this comment.
| @config "../tailwind.config.js";" | |
| @config "../tailwind.config.js"; |
Inject the `@config` in a sensible place: 1. Above the first `@theme` 2. Below the last `@import` 3. At the top of the file
If you have a setup where you have an index.css file, which in turn imports 2 new files with Tailwind CSS imports. In that case we want to inject the `@config` into the root, not in the individual files. Input: ``` --- ./src/root.4.css --- /* Inject missing @config due to nested imports with tailwind imports */ @import './root.4/base.css'; @import './root.4/utilities.css'; --- ./src/root.4/base.css --- @import 'tailwindcss/base'; --- ./src/root.4/utilities.css --- @import 'tailwindcss/utilities'; ``` Output: ``` --- ./src/root.4.css --- /* Inject missing @config due to nested imports with tailwind imports */ @import './root.4/base.css'; @import './root.4/utilities.css'; @config "../tailwind.config.ts"; --- ./src/root.4/base.css --- @import 'tailwindcss/theme' layer(theme); @import 'tailwindcss/preflight' layer(base); --- ./src/root.4/utilities.css --- @import 'tailwindcss/utilities' layer(utilities);" ```
This is the same setup as in `./packages/@tailwindcss-vite/src/index.ts`
If a non-root file contains `@import "tailwindcss"` (without its individual imports), then we can inject the `@config` in this file as well. This makes it more co-located with where you setup Tailwind CSS
This reverts commit d40e230.
baa6ffb to
754190e
Compare
If not, some files could look weird: ``` @import "tailwind.css";" ``` Which feels wrong, but the last `"` is coming from the `toMatchInlineSnapshot()` function.
This PR injects a
@config "…"in the CSS file if a JS based config has been found.We will try to inject the
@configin a sensible place:@theme@import