Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ public/schema.json

.turbo/

_pagefind/
_pagefind/
# rspress build output
apps/website/doc_build/
apps/website/docs/public/schema.json
69 changes: 69 additions & 0 deletions apps/website/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# swc-site-rspress

Rspress migration of the SWC docs site (`apps/website`, Nextra 4 → Rspress v2 / `@rspress/core@2.0.16`).

## Commands

```bash
pnpm install --ignore-workspace # installed standalone; root workspace uses pnpm 8 overrides for the Next.js apps
pnpm dev # dev server
pnpm build # static build into doc_build/
pnpm preview # serve the built site
```

## Layout

- `docs/` — all content migrated from `../website/content` (same URL structure: `/docs/...`, archived `/blog/...` routes, `/playground/`).
- `docs/_nav.json` — top navbar (Docs / Playground). In Rspress v2 the root nav file is `_nav.json`, not `_meta.json`.
- `docs/public/` — static assets copied from `../website/public` (minus Nextra-only `stork.wasm`; `schema.json` is generated by the old site's `typescript-json-schema` step and was not carried over).
- `theme/` — Rspress custom theme entry (see "Theme alignment" below).
- `src/components/` — React ports of the old site's components, stripped of Next.js (`next/link`, `next/dynamic`) and Tailwind:
- `Callout` — drop-in replacement for Nextra's `<Callout>` (keeps `type` / `emoji` props).
- `Benchmark` — chart.js 4 + react-chartjs-2 5, wrapped in `<BrowserOnly>` from `@rspress/core/runtime`.
- `Authors`, `TeamMembers`, `Customers`, `TypeDeclarations` — styled via `src/styles/index.css` (registered through `globalStyles`).
- `scripts/migrate-content.mjs` — historical: the one-shot converter used for the Nextra → Rspress migration. The Nextra source app has been removed, so it can no longer run; kept for reference.

## Conversion notes (Nextra → Rspress v2)

| Nextra | Rspress v2 |
| -------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- |
| `_meta.js` (object) | `_meta.json` (array); file labels come from each page's `#` h1 |
| `import { Callout, Tabs, Tab } from 'nextra/components'` | `import { Tab, Tabs } from '@rspress/core/theme'` + local `@components/Callout` |
| `<Tabs items={['a','b']}>` / `<Tabs.Tab>` | `<Tabs>` / `<Tab label="a">` |
| ` ```js filename="x.js" copy ` | ` ```js title="x.js" ` (copy button is built in) |
| Top-level `app/_meta.js` nav | root `docs/_nav.json` (nav array). Do not set `themeConfig.nav` — it replaces the auto-generated nav |
| Custom homepage MDX + Tailwind | `pageType: doc` plus scoped CSS preserving the original content and layout |
| Pagefind search (`postbuild`) | built-in full-text search |

Twoslash (`@rspress/plugin-twoslash`) is enabled with its default explicit trigger: tag a fence with ` ```ts twoslash ` to get type-hover popups and `// ^?` type queries. It is applied to the SWC API snippets in `usage/core.mdx`, `usage/flow.mdx`, `usage/html.mdx`, `usage/wasm.mdx`, and `references/wasm-typescript.mdx`, which required:

- `@swc/core`, `@swc/html`, `@swc/wasm-web`, `@swc/wasm-typescript`, and `@types/node` as devDependencies (snippets are really type-checked at build time).
- Plugin `compilerOptions`: `types: ["node"]`, ESNext target/module (snippets use top-level await), bundler module resolution, and `jsx: react-jsx` for the `@swc/wasm-web` React example.
- Converting the core/flow snippets from `const swc = require(...)` to `import * as swc from "@swc/core"`: the transformer only processes `ts`/`tsx` fences (that filter is not configurable through the plugin), and in a `.ts` context bare `require()` types as `any`, which kills the hovers.

Left untagged: `usage/cli.mdx`'s `swcDir` example (`@swc/cli` publishes no type definitions), the pseudo-code `minify` block in `usage/core.mdx`, `<TypeDeclarations>` dumps (they reference undeclared types), and bundler/webpack/jest config blocks.

Rspress v2 specifics (vs v1):

- All imports come from `@rspress/core/*`: `defineConfig` from `@rspress/core`, components from `@rspress/core/theme`, hooks/`BrowserOnly` from `@rspress/core/runtime`. The `rspress` npm package is v1-only; the `rspress` CLI binary ships with `@rspress/core`.
- The root nav file must be named `_nav.json` (v2 errors on a top-level `_meta.json`).
- `NoSSR` was removed; `BrowserOnly` takes a render-function child: `<BrowserOnly>{() => <Chart />}</BrowserOnly>`.
- v2 has a built-in dead-link checker that fails the build. It caught one broken link carried over from the original docs (`/docs/usage-swc-loader/` → fixed to `/docs/usage/swc-loader` in `configuration/compilation.mdx`).
- v2 server-renders **all** tab panels (v1 only rendered the active one), matching Nextra's behavior.
- `package.json` needs `"type": "module"` (the config file is loaded as ESM).

## Theme alignment

`theme/index.tsx` + `theme/index.css` (v2 custom-theme entry: named exports re-exported from `@rspress/core/theme-original`; never import `@rspress/core/theme` inside `theme/` — it resolves to this file and loops):

- Brand palette and backgrounds match Nextra's original light/dark values (hues 212/204 and backgrounds `#fafafa`/`#111`).
- `navTitle` restores the original logo, "SWC", and "Speedy Web Compiler" treatment.
- `bottom` renders the "Powered by Vercel" footer (with the original SVG) on every page.
- Head tags (favicons, webmanifest, mask-icon, twitter card/site, theme-color) are injected via `builderConfig.html.tags` in `rspress.config.ts`.
- Sidebar labels that differ from page h1s (`.swcrc`, `@swc/wasm`, `Bundling`, `Selecting swc_core`, …) are pinned with `{ "type": "file", "label": ... }` entries in the `_meta.json` files.

Behavioral notes:

- `docs/migrating-from-tsc` was unlisted in the old `_meta.js` but is now listed in the sidebar.
- Blog posts remain available as archives at their existing URLs but are intentionally omitted from the navbar and homepage.
- Nextra's "Question? Give us feedback" doc-footer link has no direct equivalent; the edit-on-GitHub link covers that flow.
23 changes: 0 additions & 23 deletions apps/website/app/[[...mdxPath]]/page.jsx

This file was deleted.

19 changes: 0 additions & 19 deletions apps/website/app/_meta.js

This file was deleted.

123 changes: 0 additions & 123 deletions apps/website/app/layout.jsx

This file was deleted.

24 changes: 0 additions & 24 deletions apps/website/components/Customers.jsx

This file was deleted.

70 changes: 0 additions & 70 deletions apps/website/components/TeamMembers.jsx

This file was deleted.

8 changes: 0 additions & 8 deletions apps/website/components/TypeDeclarations.jsx

This file was deleted.

22 changes: 0 additions & 22 deletions apps/website/components/authors.js

This file was deleted.

5 changes: 0 additions & 5 deletions apps/website/components/benchmarks/dynamic.jsx

This file was deleted.

8 changes: 0 additions & 8 deletions apps/website/components/benchmarks/styles.module.css

This file was deleted.

4 changes: 0 additions & 4 deletions apps/website/content/blog/_meta.js

This file was deleted.

Loading
Loading