Skip to content

Commit 93de4ce

Browse files
committedNov 8, 2024
fix(tailwind): TailwindConfig type broken when tailwindcss is not installed (#1740)
1 parent 1fed8fe commit 93de4ce

File tree

5 files changed

+209
-137
lines changed

5 files changed

+209
-137
lines changed
 

‎.changeset/wise-suits-run.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@react-email/tailwind": patch
3+
---
4+
5+
Fix TailwindConfig's type broken when tailwindcss is not installed on the user's project
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { promises as fs } from "node:fs";
2+
import path from "node:path";
3+
import url from "node:url";
4+
5+
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
6+
7+
await fs.cp(
8+
path.resolve(__dirname, "./node_modules/tailwindcss/types"),
9+
path.resolve(__dirname, "./dist/tailwindcss"),
10+
{
11+
recursive: true
12+
}
13+
);

‎packages/tailwind/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
},
2424
"license": "MIT",
2525
"scripts": {
26-
"build": "tsc && NODE_ENV=production vite build --mode production",
26+
"build": "tsc && NODE_ENV=production vite build --mode production && node ./copy-tailwind-types.mjs",
2727
"dev": "vite build --watch",
2828
"clean": "rm -rf dist",
2929
"lint": "eslint .",
@@ -68,7 +68,7 @@
6868
"tsup": "7.2.0",
6969
"typescript": "5.1.6",
7070
"vite": "5.1.8",
71-
"vite-plugin-dts": "3.6.3",
71+
"vite-plugin-dts": "4.2.4",
7272
"vitest": "1.1.1",
7373
"yalc": "1.0.0-pre.53"
7474
},

‎packages/tailwind/vite.config.ts

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1-
import { resolve } from "node:path";
1+
import path from "node:path";
22
import { defineConfig } from "vite";
33
import dts from "vite-plugin-dts";
44

55
export default defineConfig({
6-
plugins: [dts({ include: ["src"], outDir: "dist" })],
6+
plugins: [
7+
dts({
8+
include: ["src"],
9+
compilerOptions: {
10+
paths: {
11+
tailwindcss: [path.resolve(__dirname, "./dist/tailwindcss")],
12+
},
13+
},
14+
rollupTypes: true,
15+
outDir: "dist",
16+
}),
17+
],
718
build: {
819
rollupOptions: {
920
// in summary, this bundles the following since vite defaults to bundling
@@ -13,7 +24,7 @@ export default defineConfig({
1324
external: ["react", /^react\/.*/, "react-dom", /react-dom\/.*/],
1425
},
1526
lib: {
16-
entry: resolve(__dirname, "src/index.ts"),
27+
entry: path.resolve(__dirname, "src/index.ts"),
1728
fileName: "index",
1829
formats: ["es", "cjs"],
1930
},

‎pnpm-lock.yaml

+175-132
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.