Replies: 3 comments
-
Whoa what a great writeup, looks like you've been on a journey converting the syntax over 🤦 I noticed a small misunderstanding and just wanted to address what's short css and what's not.
The top example is short css and the bottom one is an official tailwind syntax called an arbitrary value. That should just mean a simple change to the regex: tw(.*?)((=")|`)((?!["`])[\s\S\n])*?[a-z]\[ Anyone picking this up: |
Beta Was this translation helpful? Give feedback.
-
🤣 Thanks for the clarification Ben! I will edit the initial post so as not to mislead others on that point. The regex you proposed almost works but there's a hitch: there are dashes in some properties like This took some tinkering but here is what I think is a solid find/replace:
😅 Successfully leaves the valid shorthand css ending in dash. Thanks for looking at it Ben! I still think a code mod would be a good idea BTW, since you do have to run this a bunch of times before you get them all. |
Beta Was this translation helpful? Give feedback.
-
Another little improvement -- it was missing a case where a backtick string contained
edit: also using |
Beta Was this translation helpful? Give feedback.
-
Wanted to kick off a discussion about automating the upgrade to V3 syntax.
If you don't want to read this detailed post, upvote / leave an emoji if this is something your team wants or needs! 👍
Background
Upgrading existing projects that use V2 short-css syntax like
line-height-[1.15]
to V3 can be avoided for a while with thedisableShortCss
config, but eventually will want to be upgraded to the newer tailwind syntax:[line-height:1.15]
. Something I chatted with Ben about a while back is using a code-mod utility like jscodeshift to automate this tedious process. I haven't started doing this yet, but I did the manual conversion process for one of our V2 projects, and wanted to share my learnings to kick off the idea.There are several V2 flavors we need to be aware of (and might be more than these?):
**Edit: this part of the post contains incorrect information, see Ben's reply **
The first one is easiest because it's literal, you just need to move the bracket to the start and add in a colon.
Also, we use Emotion so the following might be specific to that.
Starting with Regex
Here's an impossible-to-read regex I was able to use in VS Code to locate all (I think?) of our V2 short CSS:
I used case-sensitive regex search only on tsx files in our project (could be jsx in yours)
Part 1 is this chunk:
Part 2 is crazy but take it as an optional, non-greedy multi-line match of anything EXCEPT double-quote or backtick
Part 3 finds the opening bracket, but states that it should be preceded by a lowercase letter or a dash:
Edit: the last step above isn't quite right, see below
Gotcha: Because the expression is so complex, it will only find the first shorthand after any given
tw
, which means that during find/replace, I had to run the replacement multiple times until it came up with no matches.Codemod Challenge
Edited to avoid confusion
The codemod would probably need to do something like this:
The above might leave out some cases but should be enough for someone to get started creating the mod -- please post here if you're excited to work on this! 💯
Beta Was this translation helpful? Give feedback.
All reactions