-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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
packages/@tailwindcss-upgrade/src/codemods/migrate-at-config.ts
Outdated
Show resolved
Hide resolved
packages/@tailwindcss-upgrade/src/codemods/migrate-at-config.ts
Outdated
Show resolved
Hide resolved
cf0be89
to
f1513ab
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 @variant
s and so on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha yep I would need it right away, let's pair on this afterwards 👍
15bea44
to
589d0e8
Compare
d242cca
to
baa6ffb
Compare
integrations/upgrade/index.test.ts
Outdated
|
||
--- ./src/input.css --- | ||
@import 'tailwindcss'; | ||
@config "../tailwind.config.js";" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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
@config
in a sensible place:@theme
@import