Skip to content

Commit 35dfc53

Browse files
authored
refactor(tailwindcss): Switch to V2 + Vite (#489)
1 parent 60b3cfa commit 35dfc53

File tree

12 files changed

+160
-55
lines changed

12 files changed

+160
-55
lines changed

tailwindcss/.eslintrc.cjs

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/**
2+
* This is intended to be a basic starting point for linting in your app.
3+
* It relies on recommended configs out of the box for simplicity, but you can
4+
* and should modify this configuration to best suit your team's needs.
5+
*/
6+
7+
/** @type {import('eslint').Linter.Config} */
8+
module.exports = {
9+
root: true,
10+
parserOptions: {
11+
ecmaVersion: "latest",
12+
sourceType: "module",
13+
ecmaFeatures: {
14+
jsx: true,
15+
},
16+
},
17+
env: {
18+
browser: true,
19+
commonjs: true,
20+
es6: true,
21+
},
22+
ignorePatterns: ["!**/.server", "!**/.client"],
23+
24+
// Base config
25+
extends: ["eslint:recommended"],
26+
27+
overrides: [
28+
// React
29+
{
30+
files: ["**/*.{js,jsx,ts,tsx}"],
31+
plugins: ["react", "jsx-a11y"],
32+
extends: [
33+
"plugin:react/recommended",
34+
"plugin:react/jsx-runtime",
35+
"plugin:react-hooks/recommended",
36+
"plugin:jsx-a11y/recommended",
37+
],
38+
settings: {
39+
react: {
40+
version: "detect",
41+
},
42+
formComponents: ["Form"],
43+
linkComponents: [
44+
{ name: "Link", linkAttribute: "to" },
45+
{ name: "NavLink", linkAttribute: "to" },
46+
],
47+
"import/resolver": {
48+
typescript: {},
49+
},
50+
},
51+
},
52+
53+
// Typescript
54+
{
55+
files: ["**/*.{ts,tsx}"],
56+
plugins: ["@typescript-eslint", "import"],
57+
parser: "@typescript-eslint/parser",
58+
settings: {
59+
"import/internal-regex": "^~/",
60+
"import/resolver": {
61+
node: {
62+
extensions: [".ts", ".tsx"],
63+
},
64+
typescript: {
65+
alwaysTryTypes: true,
66+
},
67+
},
68+
},
69+
extends: [
70+
"plugin:@typescript-eslint/recommended",
71+
"plugin:import/recommended",
72+
"plugin:import/typescript",
73+
],
74+
},
75+
76+
// Node
77+
{
78+
files: [".eslintrc.cjs"],
79+
env: {
80+
node: true,
81+
},
82+
},
83+
],
84+
};

tailwindcss/.eslintrc.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

tailwindcss/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ node_modules
22

33
/.cache
44
/build
5-
/public/build
65
.env

tailwindcss/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,12 @@ Open this example on [CodeSandbox](https://codesandbox.io/s/remix-tailwind-2x8pg
1010

1111
## Example
1212

13-
This example shows how to use Tailwind CSS (v3.0) with Remix. It follows the steps outlined in the official [Remix Styling docs](https://remix.run/guides/styling#tailwind).
13+
This example shows how to use Tailwind CSS (v3.0) with Remix. It's using Vite's built-in PostCSS support.
1414

1515
Relevant files:
1616

17-
- [package.json](./package.json) where the tailwind CLI is used.
1817
- [tailwind.config.ts](./tailwind.config.ts) where tailwind is configured.
1918
- [app/root.tsx](./app/root.tsx) where tailwind is imported.
20-
- [.gitignore](.gitignore) where the generated tailwind.css is added to the ignore list.
2119

2220
## Related Links
2321

tailwindcss/app/root.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,36 @@
11
import type { LinksFunction } from "@remix-run/node";
22
import {
33
Links,
4-
LiveReload,
54
Meta,
65
Outlet,
76
Scripts,
87
ScrollRestoration,
98
} from "@remix-run/react";
109

11-
import stylesheet from "~/tailwind.css";
10+
import stylesheet from "~/tailwind.css?url";
1211

1312
export const links: LinksFunction = () => [
1413
{ rel: "stylesheet", href: stylesheet },
1514
];
1615

17-
export default function App() {
16+
export function Layout({ children }: { children: React.ReactNode }) {
1817
return (
1918
<html lang="en">
2019
<head>
2120
<meta charSet="utf-8" />
22-
<meta name="viewport" content="width=device-width,initial-scale=1" />
21+
<meta name="viewport" content="width=device-width, initial-scale=1" />
2322
<Meta />
2423
<Links />
2524
</head>
2625
<body>
27-
<Outlet />
26+
{children}
2827
<ScrollRestoration />
2928
<Scripts />
30-
<LiveReload />
3129
</body>
3230
</html>
3331
);
3432
}
33+
34+
export default function App() {
35+
return <Outlet />;
36+
}

tailwindcss/package.json

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,43 @@
11
{
2+
"name": "tailwindcss",
23
"private": true,
34
"sideEffects": false,
5+
"type": "module",
46
"scripts": {
5-
"build": "remix build",
6-
"dev": "remix dev",
7-
"start": "remix-serve build",
7+
"build": "remix vite:build",
8+
"dev": "remix vite:dev",
9+
"lint": "eslint --ignore-path .gitignore --cache --cache-location ./node_modules/.cache/eslint .",
10+
"start": "remix-serve ./build/server/index.js",
811
"typecheck": "tsc"
912
},
1013
"dependencies": {
11-
"@remix-run/node": "~1.16.0",
12-
"@remix-run/react": "~1.16.0",
13-
"@remix-run/serve": "~1.16.0",
14-
"isbot": "^3.6.5",
14+
"@remix-run/node": "^2.9.2",
15+
"@remix-run/react": "^2.9.2",
16+
"@remix-run/serve": "^2.9.2",
17+
"isbot": "^4.1.0",
1518
"react": "^18.2.0",
1619
"react-dom": "^18.2.0"
1720
},
1821
"devDependencies": {
19-
"@remix-run/dev": "~1.16.0",
20-
"@remix-run/eslint-config": "~1.16.0",
21-
"@types/react": "^18.0.25",
22-
"@types/react-dom": "^18.0.8",
23-
"eslint": "^8.27.0",
24-
"npm-run-all": "^4.1.5",
25-
"prettier-plugin-tailwindcss": "^0.2.3",
26-
"tailwindcss": "^3.3.0",
27-
"typescript": "^4.8.4"
22+
"@remix-run/dev": "^2.9.2",
23+
"@types/react": "^18.2.20",
24+
"@types/react-dom": "^18.2.7",
25+
"@typescript-eslint/eslint-plugin": "^6.7.4",
26+
"@typescript-eslint/parser": "^6.7.4",
27+
"autoprefixer": "^10.4.18",
28+
"eslint": "^8.38.0",
29+
"eslint-import-resolver-typescript": "^3.6.1",
30+
"eslint-plugin-import": "^2.28.1",
31+
"eslint-plugin-jsx-a11y": "^6.7.1",
32+
"eslint-plugin-react": "^7.33.2",
33+
"eslint-plugin-react-hooks": "^4.6.0",
34+
"postcss": "^8.4.35",
35+
"tailwindcss": "^3.4.3",
36+
"typescript": "^5.1.6",
37+
"vite": "^5.1.0",
38+
"vite-tsconfig-paths": "^4.2.1"
2839
},
2940
"engines": {
30-
"node": ">=14.0.0"
41+
"node": ">=20.0.0"
3142
}
32-
}
43+
}

tailwindcss/postcss.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default {
2+
plugins: {
3+
tailwindcss: {},
4+
autoprefixer: {},
5+
},
6+
}

tailwindcss/remix.config.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

tailwindcss/remix.env.d.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

tailwindcss/sandbox.config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"hardReloadOnChange": true,
33
"template": "remix",
44
"container": {
5-
"port": 3000
5+
"port": 5173
66
}
77
}

0 commit comments

Comments
 (0)