Skip to content
This repository was archived by the owner on Jul 24, 2025. It is now read-only.

Commit 4b9b2d5

Browse files
committed
feat: support TS/JSX inside node_modules
1 parent 6be7e50 commit 4b9b2d5

15 files changed

Lines changed: 321 additions & 8 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
node_modules/
33
dist/
44
playground-temp/
5+
test-results/
56
.swc/

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- Support TS/JSX in node_modules to help the community experiment with it. Note that for now this not supported by TS and errors from these files cannot be silenced if the user is using a stricter configuration than the library author: https://github.com/microsoft/TypeScript/issues/30511. I advise to use it only for internal libraries for now (fixes #53)
6+
57
## 3.2.0
68

79
- Support HMR for MDX (fixes #52)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { expect, test } from "@playwright/test";
2+
import { setupDevServer, setupBuildAndPreview } from "../../utils.ts";
3+
4+
test("TS lib build", async ({ page }) => {
5+
const { testUrl, server } = await setupBuildAndPreview("ts-lib");
6+
await page.goto(testUrl);
7+
await expect(page.locator("main")).toHaveText("Home page");
8+
9+
await page.locator("a", { hasText: "About" }).click();
10+
await expect(page.locator("main")).toHaveText("About page");
11+
12+
await server.httpServer.close();
13+
});
14+
15+
test("TS lib dev", async ({ page }) => {
16+
const { testUrl, server } = await setupDevServer("ts-lib");
17+
await page.goto(testUrl);
18+
await expect(page.locator("main")).toHaveText("Home page");
19+
20+
await page.locator("a", { hasText: "About" }).click();
21+
await expect(page.locator("main")).toHaveText("About page");
22+
23+
await server.close();
24+
});

playground/ts-lib/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Vite + React + TS lib</title>
8+
</head>
9+
<body>
10+
<div id="root"></div>
11+
<script type="module" src="/src/index.tsx"></script>
12+
</body>
13+
</html>

playground/ts-lib/package.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "playground-ts-lib",
3+
"type": "module",
4+
"private": true,
5+
"scripts": {
6+
"dev": "vite",
7+
"build": "vite build",
8+
"preview": "vite preview"
9+
},
10+
"dependencies": {
11+
"@generouted/react-router": "^1.11.7",
12+
"generouted": "^1.11.7",
13+
"react": "^18.2.0",
14+
"react-dom": "^18.2.0",
15+
"react-router-dom": "^6.9.0"
16+
},
17+
"devDependencies": {
18+
"@types/react": "^18.0.29",
19+
"@types/react-dom": "^18.0.11",
20+
"@vitejs/plugin-react-swc": "../../dist"
21+
}
22+
}

playground/ts-lib/public/vite.svg

Lines changed: 1 addition & 0 deletions
Loading

playground/ts-lib/src/index.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { StrictMode } from "react";
2+
import { createRoot } from "react-dom/client";
3+
import { Routes } from "generouted/react-router";
4+
5+
createRoot(document.getElementById("root")!).render(
6+
<StrictMode>
7+
<Routes />
8+
</StrictMode>,
9+
);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function NotFound() {
2+
return <h1>404</h1>
3+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Link, Outlet } from "react-router-dom";
2+
3+
export default function App() {
4+
return (
5+
<section style={{ margin: 24 }}>
6+
<header style={{ display: "flex", gap: 24 }}>
7+
<Link to="/">Home</Link>
8+
<Link to="/about">About</Link>
9+
</header>
10+
11+
<main>
12+
<Outlet />
13+
</main>
14+
</section>
15+
);
16+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function About() {
2+
return <h1>About page</h1>;
3+
}

0 commit comments

Comments
 (0)