Skip to content

Commit

Permalink
docs: better deprecation guide
Browse files Browse the repository at this point in the history
  • Loading branch information
Gnarus-G committed Mar 10, 2024
1 parent 476ca4b commit f19756a
Showing 1 changed file with 22 additions and 36 deletions.
58 changes: 22 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,71 +35,57 @@ in the old `tailwind.config.js`.
In the root of your project. Run:

```sh
echo '@tailwind utilities;' > temp.css
echo '@tailwind base; @tailwind components; @tailwind utilities;' > temp.css
npx tailwindcss -i temp.css -o legacy-tw.css
cnat prefix -i legacy-tw.css --prefix 'legacy-' ./src
```

By default, `cnat prefix` will crawl through all the `class=*`, `className=*` in jsx elements and `className:*` in a `React.createElement` calls, inside of `ts|js|tsx|jsx` files.
It will match any class in the source code with classes found in `legacy-tw.css` (which contains every style that tailwind generates based on your config).

Add the prefix in the legacy config file.

**Pro Tip**: Run your code formatter before running `cnat`. Check the formatted code into version control.
Then run the command, and run your code formatter again. Now you can go through and check the git diffs to make sure everything is
allright.

```ts
export default {
prefix: "legacy-",
};
```
By default, `cnat prefix` will crawl through all the `class=*`, `className=*` in jsx elements and `className:*` in a `React.createElement` calls, inside of `ts|js|tsx|jsx` files.
It will match any class in the source code with classes found in `legacy-tw.css` (which contains every style that tailwind generates based on your config).

Then update your global css with the tailwind directives. Rename the file for the old configs, `tailwind.legacy.config.ts`.
Rename the file for the old configs, `tailwind.legacy.config.ts`.

```sh
mv tailwind.config.ts tailwind.legacy.config.ts # or *.js if your tailwind config files aren't in typescript
```

Then, create an additional css file which the tailwind directives as such:

`./legacy-tw.css`
Add the prefix in the legacy config file.

```css
/* Make sure this is a real path in case you css file isn't at the root of the project. */
@config "./tailwind.legacy.config.ts";
@tailwind base;
@tailwind components;
@tailwind utilities;
```ts
export default {
prefix: "legacy-",
};
```

`@config` requires tailwind v3.2 btw.

Import that css file in where-ever the entry point for your project is. For example in Nextjs, you can add it to the `_app.tsx` file (pages directory version).

Now you can init new configs.
Run the tailwind cli again to rebuild the legacy css classes. Now they will be prefixed since the `tailwind.legacy.config.ts` defined
the 'legacy-'

```sh
npx tailwindcss init
npx tailwindcss -i temp.css -o legacy-tw.css -c tailwind.legacy.config.ts
```

Now in a new `global.css` file
Then, import the legacy css into your global css file.

```css
/* Again mind the path. */
@config "./tailwind.config.ts"
@tailwind base;
@import "./legacy-tw.css" @tailwind base;
@tailwind components;
@tailwind utilities;

/* And whatever else you have in here */
```

```ts
// Again mind the paths.
import "./legacy-tw.css";
import "./global.css";
Now you can re-init new configs.

```sh
# You'd have to delete the current `tailwind.config.ts` if you haven't already.
npx tailwindcss init --ts
```

And now you can breathe.
And now you can breathe. A fresh new start; ignoring what's under the bed now.

## Usage

Expand Down

0 comments on commit f19756a

Please sign in to comment.