From 464cd411c988bc7e27a852fd9a80c0b9af0ea080 Mon Sep 17 00:00:00 2001 From: DongYun Kang Date: Fri, 10 Jul 2026 17:07:04 +0900 Subject: [PATCH 1/4] Reapply "refactor: Migrate docs site from Nextra to Rspress v2" (#323) This reverts commit e7ea679e804b057333112d0f8dd8598b3abc4406. --- .gitignore | 5 +- apps/website/README.md | 67 + apps/website/app/[[...mdxPath]]/page.jsx | 23 - apps/website/app/_meta.js | 19 - apps/website/app/layout.jsx | 123 - apps/website/components/Customers.jsx | 24 - apps/website/components/TeamMembers.jsx | 70 - apps/website/components/TypeDeclarations.jsx | 8 - apps/website/components/authors.js | 22 - .../website/components/benchmarks/dynamic.jsx | 5 - .../components/benchmarks/styles.module.css | 8 - apps/website/content/blog/_meta.js | 4 - apps/website/content/docs/_meta.js | 15 - .../content/docs/configuration/_meta.js | 8 - .../content/docs/contributing/_meta.js | 5 - .../docs/contributing/commons/_meta.js | 3 - .../docs/contributing/es-commons/_meta.js | 3 - .../docs/contributing/es-minifier/_meta.js | 4 - apps/website/content/docs/plugin/_meta.js | 6 - .../content/docs/plugin/ecmascript/_meta.js | 5 - apps/website/content/docs/references/_meta.js | 3 - apps/website/content/docs/usage/_meta.js | 10 - apps/website/content/index.mdx | 99 - apps/website/content/playground/_meta.js | 5 - apps/website/docs/_nav.json | 17 + apps/website/docs/blog/_meta.json | 1 + .../blog/perf-swc-vs-babel.mdx | 2 +- apps/website/{content => docs}/blog/swc-1.mdx | 2 +- apps/website/docs/docs/_meta.json | 16 + .../{content => docs}/docs/benchmarks.mdx | 2 +- .../docs/docs/configuration/_meta.json | 8 + .../docs/configuration/bundling.mdx | 8 +- .../docs/configuration/compilation.mdx | 68 +- .../docs/configuration/minification.mdx | 29 +- .../docs/configuration/modules.mdx | 23 +- .../docs/configuration/supported-browsers.mdx | 10 +- .../docs/configuration/swcrc.mdx | 10 +- .../website/docs/docs/contributing/_meta.json | 5 + .../docs/docs/contributing/commons/_meta.json | 1 + .../commons/string-management.mdx | 4 + .../docs/contributing/es-commons/_meta.json | 1 + .../es-commons/variable-management.mdx | 0 .../docs/contributing/es-minifier/_meta.json | 9 + .../es-minifier/debugging-nextjs-app.mdx | 4 + .../es-minifier/debugging-size.mdx | 0 .../contributing/es-minifier/profiling.mdx | 0 .../{content => docs}/docs/customers.mdx | 2 +- .../docs/getting-started.mdx | 19 +- .../docs/migrating-from-babel.md | 0 .../docs/migrating-from-tsc.md | 0 apps/website/docs/docs/plugin/_meta.json | 14 + .../docs/docs/plugin/ecmascript/_meta.json | 5 + .../docs/plugin/ecmascript/cheatsheet.mdx | 4 +- .../docs/plugin/ecmascript/compatibility.mdx | 0 .../ecmascript/compatibility/overview.png | Bin .../plugin/ecmascript/getting-started.mdx | 2 +- .../docs/plugin/publishing.mdx | 4 +- .../docs/plugin/registering-plugins.mdx | 0 .../docs/plugin/selecting-swc-core.mdx | 0 apps/website/docs/docs/references/_meta.json | 1 + .../docs/references/wasm-typescript.mdx | 2 +- .../website/{content => docs}/docs/roadmap.md | 0 .../{content => docs}/docs/sponsors.mdx | 0 .../{content => docs}/docs/swc-node-vs-swc.md | 0 apps/website/{content => docs}/docs/team.mdx | 2 +- apps/website/docs/docs/usage/_meta.json | 10 + .../{content => docs}/docs/usage/bundling.mdx | 41 +- .../{content => docs}/docs/usage/cli.mdx | 28 +- .../{content => docs}/docs/usage/core.mdx | 15 +- .../{content => docs}/docs/usage/flow.mdx | 22 +- .../{content => docs}/docs/usage/html.mdx | 34 +- .../{content => docs}/docs/usage/jest.mdx | 34 +- .../docs/usage/swc-loader.mdx | 28 +- .../{content => docs}/docs/usage/wasm.mdx | 2 +- apps/website/docs/index.mdx | 89 + .../{content => docs}/playground/index.mdx | 10 +- .../favicon => docs/public}/favicon.ico | Bin .../public/favicon/android-chrome-192x192.png | Bin .../public/favicon/android-chrome-512x512.png | Bin .../public/favicon/apple-touch-icon.png | Bin .../public/favicon/browserconfig.xml | 0 .../public/favicon/favicon-16x16.png | Bin .../public/favicon/favicon-32x32.png | Bin apps/website/docs/public/favicon/favicon.ico | Bin 0 -> 15086 bytes .../public/favicon/mstile-150x150.png | Bin .../public/favicon/safari-pinned-tab.svg | 0 .../docs/public/favicon/site.webmanifest | 19 + .../public/img/customers/affine.svg | 0 .../public/img/customers/apimaker.svg | 0 .../{ => docs}/public/img/customers/artsy.svg | 0 .../public/img/customers/bytedance.png | Bin .../{ => docs}/public/img/customers/deno.svg | 0 .../public/img/customers/digitec.jpg | Bin .../public/img/customers/evershop.png | Bin .../public/img/customers/fireworks.svg | 0 .../public/img/customers/framer.svg | 0 .../public/img/customers/fundamentei.png | Bin .../public/img/customers/galaxus.jpg | Bin .../public/img/customers/hennge.svg | 0 .../public/img/customers/landfolk.svg | 0 .../public/img/customers/mediaboard.svg | 0 .../{ => docs}/public/img/customers/miro.svg | 0 .../public/img/customers/octopol.jpeg | Bin .../public/img/customers/parceljs.png | Bin .../public/img/customers/pollen.png | Bin .../public/img/customers/shopify.svg | 0 .../public/img/customers/strapi.svg | 0 .../public/img/customers/supabase.png | Bin .../public/img/customers/tencent.svg | 0 .../public/img/customers/the-media-ant.webp | Bin .../public/img/customers/transloadit.svg | 0 .../{ => docs}/public/img/customers/trip.png | Bin .../public/img/customers/tripbiz.svg | 0 .../public/img/customers/vercel.svg | 0 .../public/img/customers/verkada.png | Bin .../public/img/customers/wayfair.svg | 0 apps/website/{ => docs}/public/logo.png | Bin apps/website/{ => docs}/public/og.png | Bin apps/website/lib/gtag.js | 17 - apps/website/mdx-components.js | 12 - apps/website/next-env.d.ts | 5 - apps/website/next.config.mjs | 125 - apps/website/package.json | 50 +- apps/website/postcss.config.js | 9 - apps/website/public/favicon/site.webmanifest | 19 - apps/website/public/schema.json | 1565 --------- apps/website/public/stork.wasm | Bin 487043 -> 0 bytes apps/website/rspress.config.ts | 175 + apps/website/scripts/migrate-content.mjs | 171 + apps/website/src/components/Authors.tsx | 25 + .../components/Benchmark.tsx} | 65 +- apps/website/src/components/Callout.tsx | 31 + apps/website/src/components/Customers.tsx | 32 + apps/website/src/components/TeamMembers.tsx | 63 + .../src/components/TypeDeclarations.tsx | 14 + apps/website/{ => src}/customers.json | 0 apps/website/src/styles/index.css | 125 + apps/website/src/types.ts | 2 + apps/website/styles.css | 1 - apps/website/theme/index.css | 41 + apps/website/theme/index.tsx | 32 + apps/website/tsconfig.json | 41 +- apps/website/tsconfig.schema.json | 4 + apps/website/types.ts | 1 - apps/website/vercel.json | 125 + pnpm-lock.yaml | 3088 +++++++++++++++-- 146 files changed, 4143 insertions(+), 2846 deletions(-) create mode 100644 apps/website/README.md delete mode 100644 apps/website/app/[[...mdxPath]]/page.jsx delete mode 100644 apps/website/app/_meta.js delete mode 100644 apps/website/app/layout.jsx delete mode 100644 apps/website/components/Customers.jsx delete mode 100644 apps/website/components/TeamMembers.jsx delete mode 100644 apps/website/components/TypeDeclarations.jsx delete mode 100644 apps/website/components/authors.js delete mode 100644 apps/website/components/benchmarks/dynamic.jsx delete mode 100644 apps/website/components/benchmarks/styles.module.css delete mode 100644 apps/website/content/blog/_meta.js delete mode 100644 apps/website/content/docs/_meta.js delete mode 100644 apps/website/content/docs/configuration/_meta.js delete mode 100644 apps/website/content/docs/contributing/_meta.js delete mode 100644 apps/website/content/docs/contributing/commons/_meta.js delete mode 100644 apps/website/content/docs/contributing/es-commons/_meta.js delete mode 100644 apps/website/content/docs/contributing/es-minifier/_meta.js delete mode 100644 apps/website/content/docs/plugin/_meta.js delete mode 100644 apps/website/content/docs/plugin/ecmascript/_meta.js delete mode 100644 apps/website/content/docs/references/_meta.js delete mode 100644 apps/website/content/docs/usage/_meta.js delete mode 100644 apps/website/content/index.mdx delete mode 100644 apps/website/content/playground/_meta.js create mode 100644 apps/website/docs/_nav.json create mode 100644 apps/website/docs/blog/_meta.json rename apps/website/{content => docs}/blog/perf-swc-vs-babel.mdx (99%) rename apps/website/{content => docs}/blog/swc-1.mdx (98%) create mode 100644 apps/website/docs/docs/_meta.json rename apps/website/{content => docs}/docs/benchmarks.mdx (98%) create mode 100644 apps/website/docs/docs/configuration/_meta.json rename apps/website/{content => docs}/docs/configuration/bundling.mdx (93%) rename apps/website/{content => docs}/docs/configuration/compilation.mdx (94%) rename apps/website/{content => docs}/docs/configuration/minification.mdx (93%) rename apps/website/{content => docs}/docs/configuration/modules.mdx (82%) rename apps/website/{content => docs}/docs/configuration/supported-browsers.mdx (94%) rename apps/website/{content => docs}/docs/configuration/swcrc.mdx (91%) create mode 100644 apps/website/docs/docs/contributing/_meta.json create mode 100644 apps/website/docs/docs/contributing/commons/_meta.json rename apps/website/{content => docs}/docs/contributing/commons/string-management.mdx (95%) create mode 100644 apps/website/docs/docs/contributing/es-commons/_meta.json rename apps/website/{content => docs}/docs/contributing/es-commons/variable-management.mdx (100%) create mode 100644 apps/website/docs/docs/contributing/es-minifier/_meta.json rename apps/website/{content => docs}/docs/contributing/es-minifier/debugging-nextjs-app.mdx (96%) rename apps/website/{content => docs}/docs/contributing/es-minifier/debugging-size.mdx (100%) rename apps/website/{content => docs}/docs/contributing/es-minifier/profiling.mdx (100%) rename apps/website/{content => docs}/docs/customers.mdx (52%) rename apps/website/{content => docs}/docs/getting-started.mdx (78%) rename apps/website/{content => docs}/docs/migrating-from-babel.md (100%) rename apps/website/{content => docs}/docs/migrating-from-tsc.md (100%) create mode 100644 apps/website/docs/docs/plugin/_meta.json create mode 100644 apps/website/docs/docs/plugin/ecmascript/_meta.json rename apps/website/{content => docs}/docs/plugin/ecmascript/cheatsheet.mdx (99%) rename apps/website/{content => docs}/docs/plugin/ecmascript/compatibility.mdx (100%) rename apps/website/{content => docs}/docs/plugin/ecmascript/compatibility/overview.png (100%) rename apps/website/{content => docs}/docs/plugin/ecmascript/getting-started.mdx (99%) rename apps/website/{content => docs}/docs/plugin/publishing.mdx (96%) rename apps/website/{content => docs}/docs/plugin/registering-plugins.mdx (100%) rename apps/website/{content => docs}/docs/plugin/selecting-swc-core.mdx (100%) create mode 100644 apps/website/docs/docs/references/_meta.json rename apps/website/{content => docs}/docs/references/wasm-typescript.mdx (97%) rename apps/website/{content => docs}/docs/roadmap.md (100%) rename apps/website/{content => docs}/docs/sponsors.mdx (100%) rename apps/website/{content => docs}/docs/swc-node-vs-swc.md (100%) rename apps/website/{content => docs}/docs/team.mdx (53%) create mode 100644 apps/website/docs/docs/usage/_meta.json rename apps/website/{content => docs}/docs/usage/bundling.mdx (87%) rename apps/website/{content => docs}/docs/usage/cli.mdx (93%) rename apps/website/{content => docs}/docs/usage/core.mdx (98%) rename apps/website/{content => docs}/docs/usage/flow.mdx (86%) rename apps/website/{content => docs}/docs/usage/html.mdx (63%) rename apps/website/{content => docs}/docs/usage/jest.mdx (82%) rename apps/website/{content => docs}/docs/usage/swc-loader.mdx (81%) rename apps/website/{content => docs}/docs/usage/wasm.mdx (96%) create mode 100644 apps/website/docs/index.mdx rename apps/website/{content => docs}/playground/index.mdx (74%) rename apps/website/{public/favicon => docs/public}/favicon.ico (100%) rename apps/website/{ => docs}/public/favicon/android-chrome-192x192.png (100%) rename apps/website/{ => docs}/public/favicon/android-chrome-512x512.png (100%) rename apps/website/{ => docs}/public/favicon/apple-touch-icon.png (100%) rename apps/website/{ => docs}/public/favicon/browserconfig.xml (100%) rename apps/website/{ => docs}/public/favicon/favicon-16x16.png (100%) rename apps/website/{ => docs}/public/favicon/favicon-32x32.png (100%) create mode 100644 apps/website/docs/public/favicon/favicon.ico rename apps/website/{ => docs}/public/favicon/mstile-150x150.png (100%) rename apps/website/{ => docs}/public/favicon/safari-pinned-tab.svg (100%) create mode 100644 apps/website/docs/public/favicon/site.webmanifest rename apps/website/{ => docs}/public/img/customers/affine.svg (100%) rename apps/website/{ => docs}/public/img/customers/apimaker.svg (100%) rename apps/website/{ => docs}/public/img/customers/artsy.svg (100%) rename apps/website/{ => docs}/public/img/customers/bytedance.png (100%) rename apps/website/{ => docs}/public/img/customers/deno.svg (100%) rename apps/website/{ => docs}/public/img/customers/digitec.jpg (100%) rename apps/website/{ => docs}/public/img/customers/evershop.png (100%) rename apps/website/{ => docs}/public/img/customers/fireworks.svg (100%) rename apps/website/{ => docs}/public/img/customers/framer.svg (100%) rename apps/website/{ => docs}/public/img/customers/fundamentei.png (100%) rename apps/website/{ => docs}/public/img/customers/galaxus.jpg (100%) rename apps/website/{ => docs}/public/img/customers/hennge.svg (100%) rename apps/website/{ => docs}/public/img/customers/landfolk.svg (100%) rename apps/website/{ => docs}/public/img/customers/mediaboard.svg (100%) rename apps/website/{ => docs}/public/img/customers/miro.svg (100%) rename apps/website/{ => docs}/public/img/customers/octopol.jpeg (100%) rename apps/website/{ => docs}/public/img/customers/parceljs.png (100%) rename apps/website/{ => docs}/public/img/customers/pollen.png (100%) rename apps/website/{ => docs}/public/img/customers/shopify.svg (100%) rename apps/website/{ => docs}/public/img/customers/strapi.svg (100%) rename apps/website/{ => docs}/public/img/customers/supabase.png (100%) rename apps/website/{ => docs}/public/img/customers/tencent.svg (100%) rename apps/website/{ => docs}/public/img/customers/the-media-ant.webp (100%) rename apps/website/{ => docs}/public/img/customers/transloadit.svg (100%) rename apps/website/{ => docs}/public/img/customers/trip.png (100%) rename apps/website/{ => docs}/public/img/customers/tripbiz.svg (100%) rename apps/website/{ => docs}/public/img/customers/vercel.svg (100%) rename apps/website/{ => docs}/public/img/customers/verkada.png (100%) rename apps/website/{ => docs}/public/img/customers/wayfair.svg (100%) rename apps/website/{ => docs}/public/logo.png (100%) rename apps/website/{ => docs}/public/og.png (100%) delete mode 100644 apps/website/lib/gtag.js delete mode 100644 apps/website/mdx-components.js delete mode 100644 apps/website/next-env.d.ts delete mode 100644 apps/website/next.config.mjs delete mode 100644 apps/website/postcss.config.js delete mode 100644 apps/website/public/favicon/site.webmanifest delete mode 100644 apps/website/public/schema.json delete mode 100644 apps/website/public/stork.wasm create mode 100644 apps/website/rspress.config.ts create mode 100644 apps/website/scripts/migrate-content.mjs create mode 100644 apps/website/src/components/Authors.tsx rename apps/website/{components/benchmarks/benchmark.jsx => src/components/Benchmark.tsx} (68%) create mode 100644 apps/website/src/components/Callout.tsx create mode 100644 apps/website/src/components/Customers.tsx create mode 100644 apps/website/src/components/TeamMembers.tsx create mode 100644 apps/website/src/components/TypeDeclarations.tsx rename apps/website/{ => src}/customers.json (100%) create mode 100644 apps/website/src/styles/index.css create mode 100644 apps/website/src/types.ts delete mode 100644 apps/website/styles.css create mode 100644 apps/website/theme/index.css create mode 100644 apps/website/theme/index.tsx create mode 100644 apps/website/tsconfig.schema.json delete mode 100644 apps/website/types.ts create mode 100644 apps/website/vercel.json diff --git a/.gitignore b/.gitignore index 27132ab8..3d2eaa63 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,7 @@ public/schema.json .turbo/ -_pagefind/ \ No newline at end of file +_pagefind/ +# rspress build output +apps/website/doc_build/ +apps/website/docs/public/schema.json diff --git a/apps/website/README.md b/apps/website/README.md new file mode 100644 index 00000000..3d606eba --- /dev/null +++ b/apps/website/README.md @@ -0,0 +1,67 @@ +# 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 1:1 from `../website/content` (same URL structure: `/docs/...`, `/blog/...`, `/playground/`). +- `docs/_nav.json` — top navbar (Docs / Playground / Blog). 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 `` (keeps `type` / `emoji` props). + - `Benchmark` — chart.js 4 + react-chartjs-2 5, wrapped in `` 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` | +| `` / `` | `` / `` | +| ` ```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: home` hero/features frontmatter | +| 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`, `` 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: `{() => }`. +- 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 overridden to Nextra's blue (hue 212) for light and dark mode. +- `bottom` slot renders the "Powered by Vercel" footer (with the original SVG) on every page. (The original site's "Speedy Web Compiler" navbar subtitle was intentionally dropped.) +- 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. +- Nextra's "Question? Give us feedback" doc-footer link has no direct equivalent; the edit-on-GitHub link covers that flow. diff --git a/apps/website/app/[[...mdxPath]]/page.jsx b/apps/website/app/[[...mdxPath]]/page.jsx deleted file mode 100644 index 54f5a0a2..00000000 --- a/apps/website/app/[[...mdxPath]]/page.jsx +++ /dev/null @@ -1,23 +0,0 @@ -import { generateStaticParamsFor, importPage } from "nextra/pages"; -import { useMDXComponents as getMDXComponents } from "../../mdx-components"; - -export const generateStaticParams = generateStaticParamsFor("mdxPath"); - -export async function generateMetadata(props) { - const params = await props.params; - const { metadata } = await importPage(params.mdxPath); - return metadata; -} - -const Wrapper = getMDXComponents().wrapper; - -export default async function Page(props) { - const params = await props.params; - const result = await importPage(params.mdxPath); - const { default: MDXContent, toc, metadata } = result; - return ( - - - - ); -} diff --git a/apps/website/app/_meta.js b/apps/website/app/_meta.js deleted file mode 100644 index 8541ad10..00000000 --- a/apps/website/app/_meta.js +++ /dev/null @@ -1,19 +0,0 @@ -export default { - index: { - title: "Introduction", - type: "page", - display: "hidden", - }, - docs: { - title: "Docs", - type: "page", - }, - playground: { - title: "Playground", - type: "page", - }, - blog: { - title: "Blog", - type: "page", - }, -}; diff --git a/apps/website/app/layout.jsx b/apps/website/app/layout.jsx deleted file mode 100644 index 72567774..00000000 --- a/apps/website/app/layout.jsx +++ /dev/null @@ -1,123 +0,0 @@ -import { Footer, Layout, Navbar } from "nextra-theme-docs"; -import { Banner, Head } from "nextra/components"; -import { getPageMap } from "nextra/page-map"; -import "nextra-theme-docs/style.css"; -import "../styles.css"; - -const Vercel = ({ height = 20 }) => ( - - - -); - -export default async function RootLayout({ children }) { - return ( - - - - - - - - - - - - {/* - */} - - - {/* - - */} - - - - - - - SWC - - - Speedy Web Compiler - - - } - projectLink="https://github.com/swc-project/swc" - chatLink="https://discord.gg/GnHbXTdZz6" - /> - } - footer={ - - Powered by - - - - - } - > - {children} - - - - ); -} diff --git a/apps/website/components/Customers.jsx b/apps/website/components/Customers.jsx deleted file mode 100644 index 86815a25..00000000 --- a/apps/website/components/Customers.jsx +++ /dev/null @@ -1,24 +0,0 @@ -import Link from "next/link"; -import customers from '../customers.json'; - -export default function Customers() { - const showcase = customers.map((customer, index) => { - const url = new URL(customer.infoLink); - url.searchParams.append("utm_source", "swc"); - url.searchParams.append("utm_medium", "customers_page"); - - return ( - - {customer.caption}/ - - ); - }); - return ( -
- {showcase} -
- ); -} diff --git a/apps/website/components/TeamMembers.jsx b/apps/website/components/TeamMembers.jsx deleted file mode 100644 index 02bc455a..00000000 --- a/apps/website/components/TeamMembers.jsx +++ /dev/null @@ -1,70 +0,0 @@ -import Link from "next/link"; - -const members = [ - { - name: "kdy1 / Donny", - link: "https://github.com/kdy1", - github: "kdy1", - role: "Lead Maintainer", - }, - { - name: "OJ Kwon", - link: "https://github.com/kwonoj", - github: "kwonoj", - role: "Core Team", - }, - { - name: "magic-akari", - link: "https://github.com/magic-akari", - github: "magic-akari", - role: "Core Team", - }, - { - name: "Austaras", - link: "https://github.com/Austaras", - github: "Austaras", - role: "Core Team", - }, - { - name: "CPunisher", - link: "https://github.com/CPunisher", - github: "CPunisher", - role: "Core Team", - }, - { - name: "bohan", - link: "https://github.com/bvanjoi", - github: "bvanjoi", - role: "Core Team", - }, - { - name: "LongYinan", - link: "https://github.com/Brooooooklyn", - github: "Brooooooklyn", - role: "Maintainer of @swc-node/*", - }, -]; - -export default function TeamMembers() { - return ( -
- {members.map((member, index) => { - return ( - -
- {`${member.name} -
{member.name}
-
{member.role}
-
- - ); - })} -
- ); -} diff --git a/apps/website/components/TypeDeclarations.jsx b/apps/website/components/TypeDeclarations.jsx deleted file mode 100644 index 1ed0232c..00000000 --- a/apps/website/components/TypeDeclarations.jsx +++ /dev/null @@ -1,8 +0,0 @@ -export default function TypeDeclarations(props) { - return ( -
- Type Declarations - {props.children} -
- ); -} diff --git a/apps/website/components/authors.js b/apps/website/components/authors.js deleted file mode 100644 index f39eaac4..00000000 --- a/apps/website/components/authors.js +++ /dev/null @@ -1,22 +0,0 @@ -export default function Authors({ date, children }) { - return ( -
- {date} by {children} -
- ); -} - -export function Author({ name, link }) { - return ( - - - {name} - - - ); -} diff --git a/apps/website/components/benchmarks/dynamic.jsx b/apps/website/components/benchmarks/dynamic.jsx deleted file mode 100644 index bb3e3786..00000000 --- a/apps/website/components/benchmarks/dynamic.jsx +++ /dev/null @@ -1,5 +0,0 @@ -import dynamic from "next/dynamic"; - -const Benchmark = dynamic(() => import("./benchmark")); - -export default Benchmark; diff --git a/apps/website/components/benchmarks/styles.module.css b/apps/website/components/benchmarks/styles.module.css deleted file mode 100644 index 18e5011e..00000000 --- a/apps/website/components/benchmarks/styles.module.css +++ /dev/null @@ -1,8 +0,0 @@ -.top { - display: flex; - justify-content: space-between; - align-items: flex-end; - flex-wrap: wrap; - row-gap: 4px; - margin: 4px 0; -} diff --git a/apps/website/content/blog/_meta.js b/apps/website/content/blog/_meta.js deleted file mode 100644 index 8afeda2e..00000000 --- a/apps/website/content/blog/_meta.js +++ /dev/null @@ -1,4 +0,0 @@ -export default { - "perf-swc-vs-babel": "Performance Comparison of SWC and Babel", - "swc-1": "Introducing SWC 1.0", -}; diff --git a/apps/website/content/docs/_meta.js b/apps/website/content/docs/_meta.js deleted file mode 100644 index 178f6244..00000000 --- a/apps/website/content/docs/_meta.js +++ /dev/null @@ -1,15 +0,0 @@ -export default { - "getting-started": "Getting Started", - usage: "Usage", - configuration: "Configuration", - plugin: "Plugin", - contributing: "Contributing", - team: "The Team", - roadmap: "Roadmap", - sponsors: "Sponsors", - customers: "Customers", - benchmarks: "Benchmarks", - references: "API References", - "migrating-from-babel": "Migrating from Babel", - "swc-node-vs-swc": "@swc-node vs @swc", -}; diff --git a/apps/website/content/docs/configuration/_meta.js b/apps/website/content/docs/configuration/_meta.js deleted file mode 100644 index c7dd2960..00000000 --- a/apps/website/content/docs/configuration/_meta.js +++ /dev/null @@ -1,8 +0,0 @@ -export default { - swcrc: ".swcrc", - compilation: "Compilation", - "supported-browsers": "Supported Browsers", - modules: "Modules", - minification: "Minification", - bundling: "Bundling", -}; diff --git a/apps/website/content/docs/contributing/_meta.js b/apps/website/content/docs/contributing/_meta.js deleted file mode 100644 index fa9e5491..00000000 --- a/apps/website/content/docs/contributing/_meta.js +++ /dev/null @@ -1,5 +0,0 @@ -export default { - commons: "Commons", - "es-commons": "ECMAScript Commons", - "es-minifier": "ECMAScript Minifier", -}; diff --git a/apps/website/content/docs/contributing/commons/_meta.js b/apps/website/content/docs/contributing/commons/_meta.js deleted file mode 100644 index 0e777f29..00000000 --- a/apps/website/content/docs/contributing/commons/_meta.js +++ /dev/null @@ -1,3 +0,0 @@ -export default { - "string-management": "String Management", -}; diff --git a/apps/website/content/docs/contributing/es-commons/_meta.js b/apps/website/content/docs/contributing/es-commons/_meta.js deleted file mode 100644 index ab18886e..00000000 --- a/apps/website/content/docs/contributing/es-commons/_meta.js +++ /dev/null @@ -1,3 +0,0 @@ -export default { - "variable-management": "Variable Management", -}; diff --git a/apps/website/content/docs/contributing/es-minifier/_meta.js b/apps/website/content/docs/contributing/es-minifier/_meta.js deleted file mode 100644 index 6027f722..00000000 --- a/apps/website/content/docs/contributing/es-minifier/_meta.js +++ /dev/null @@ -1,4 +0,0 @@ -export default { - profiling: "Profiling", - "debugging-nextjs-app": "Debugging Next.js App", -}; diff --git a/apps/website/content/docs/plugin/_meta.js b/apps/website/content/docs/plugin/_meta.js deleted file mode 100644 index f30ad05d..00000000 --- a/apps/website/content/docs/plugin/_meta.js +++ /dev/null @@ -1,6 +0,0 @@ -export default { - "selecting-swc-core": "Selecting swc_core", - ecmascript: "ECMAScript", - publishing: "Publishing", - "registering-plugins": "Registering Plugins", -}; diff --git a/apps/website/content/docs/plugin/ecmascript/_meta.js b/apps/website/content/docs/plugin/ecmascript/_meta.js deleted file mode 100644 index fe469c2d..00000000 --- a/apps/website/content/docs/plugin/ecmascript/_meta.js +++ /dev/null @@ -1,5 +0,0 @@ -export default { - "getting-started": "Getting started", - cheatsheet: "Cheatsheet", - compatibility: "Compatibility", -}; diff --git a/apps/website/content/docs/references/_meta.js b/apps/website/content/docs/references/_meta.js deleted file mode 100644 index c262c018..00000000 --- a/apps/website/content/docs/references/_meta.js +++ /dev/null @@ -1,3 +0,0 @@ -export default { - "wasm-typescript": "@swc/wasm-typescript", -}; diff --git a/apps/website/content/docs/usage/_meta.js b/apps/website/content/docs/usage/_meta.js deleted file mode 100644 index 1becb5de..00000000 --- a/apps/website/content/docs/usage/_meta.js +++ /dev/null @@ -1,10 +0,0 @@ -export default { - cli: "@swc/cli", - core: "@swc/core", - flow: "Flow", - wasm: "@swc/wasm", - jest: "@swc/jest", - "swc-loader": "swc-loader", - html: "@swc/html", - bundling: "Bundling", -}; diff --git a/apps/website/content/index.mdx b/apps/website/content/index.mdx deleted file mode 100644 index 3b4b7196..00000000 --- a/apps/website/content/index.mdx +++ /dev/null @@ -1,99 +0,0 @@ ---- -title: Rust-based platform for the Web ---- - -import { Callout, Tabs, Tab } from 'nextra/components' - -{

SWC

} - -
- {

- Rust-based platform for the Web -

} -
- -SWC is an extensible Rust-based platform for the next generation of fast developer tools. It's used by tools like Next.js, Parcel, and Deno, as well as companies like Vercel, ByteDance, Tencent, Shopify, Trip.com, and [more](/docs/customers). - -SWC can be used for both compilation and bundling. For compilation, it takes JavaScript / TypeScript files using modern JavaScript features and outputs valid code that is supported by all major browsers. - - - SWC is 20x faster than Babel on a single thread and 70x faster on four cores. - - -
- [Get Started](/docs/getting-started) · [Playground](/playground) · [Blog](/blog/perf-swc-vs-babel) · [Rustdocs](https://rustdoc.swc.rs/swc/) · [GitHub Repository](https://github.com/swc-project/swc) · [Donate](https://opencollective.com/swc) -
- -## Overview - -SWC can be downloaded and used as a pre-built binary, or built from source. Currently, the following binaries are provided: - -- Mac (Apple Silicon) -- Mac (x64) -- Linux (x86_64) -- Linux (aarch64) -- Linux (armv7) -- Alpine Linux (also install `@swc/core-linux-musl`) -- Android (aarch64) -- Windows (win32-x64) -- Windows (ia32) - -#### Download prebuilt binaries - - - - ```bash copy - pnpm add -D @swc/cli @swc/core - ``` - - - ```bash copy - npm i -D @swc/cli @swc/core - ``` - - - ```bash copy - yarn add -D @swc/cli @swc/core - ``` - - - -#### Transpile JavaScript file and emit to stdout - -```bash copy -npx swc ./file.js -``` - -## Features - -SWC is designed to be extensible. Currently, there is support for: - -- Compilation -- Minification -- Transforming with WebAssembly -- Usage inside webpack and Rspack (`swc-loader`) -- Improving Jest performance (`@swc/jest`) -- Custom Plugins - -[Learn more](/docs/getting-started). - -## Community - -
-
- stars -
- -
- downloads -
- -
- downloads -
-
- -SWC is created by [kdy1](https://github.com/kdy1). -Follow [@kdy1dev](https://twitter.com/kdy1dev) on Twitter for future project updates. - -Feel free to join the [discussions on GitHub](https://github.com/swc-project/swc/discussions)! diff --git a/apps/website/content/playground/_meta.js b/apps/website/content/playground/_meta.js deleted file mode 100644 index ea466abf..00000000 --- a/apps/website/content/playground/_meta.js +++ /dev/null @@ -1,5 +0,0 @@ -export default { - index: { - title: "Try SWC", - }, -}; diff --git a/apps/website/docs/_nav.json b/apps/website/docs/_nav.json new file mode 100644 index 00000000..05fd4e03 --- /dev/null +++ b/apps/website/docs/_nav.json @@ -0,0 +1,17 @@ +[ + { + "text": "Docs", + "link": "/docs/getting-started", + "activeMatch": "^/docs/" + }, + { + "text": "Playground", + "link": "/playground/", + "activeMatch": "^/playground/" + }, + { + "text": "Blog", + "link": "/blog/perf-swc-vs-babel", + "activeMatch": "^/blog/" + } +] diff --git a/apps/website/docs/blog/_meta.json b/apps/website/docs/blog/_meta.json new file mode 100644 index 00000000..c20b197d --- /dev/null +++ b/apps/website/docs/blog/_meta.json @@ -0,0 +1 @@ +["perf-swc-vs-babel", "swc-1"] diff --git a/apps/website/content/blog/perf-swc-vs-babel.mdx b/apps/website/docs/blog/perf-swc-vs-babel.mdx similarity index 99% rename from apps/website/content/blog/perf-swc-vs-babel.mdx rename to apps/website/docs/blog/perf-swc-vs-babel.mdx index bc03d60a..85622539 100644 --- a/apps/website/content/blog/perf-swc-vs-babel.mdx +++ b/apps/website/docs/blog/perf-swc-vs-babel.mdx @@ -3,7 +3,7 @@ image: https://user-images.githubusercontent.com/9113740/140682117-5e9f460e-c8f1 description: 'Benchmark and performance comparison of SWC and Babel.' --- -import Authors, { Author } from 'components/authors' +import Authors, { Author } from '@components/Authors'; # Performance Comparison of SWC and Babel diff --git a/apps/website/content/blog/swc-1.mdx b/apps/website/docs/blog/swc-1.mdx similarity index 98% rename from apps/website/content/blog/swc-1.mdx rename to apps/website/docs/blog/swc-1.mdx index 1d9352f9..4aa61183 100644 --- a/apps/website/content/blog/swc-1.mdx +++ b/apps/website/docs/blog/swc-1.mdx @@ -3,7 +3,7 @@ image: https://user-images.githubusercontent.com/9113740/140682117-5e9f460e-c8f1 description: 'SWC (Speedy Web Compiler) is a super-fast JavaScript and TypeScript compiler.' --- -import Authors, { Author } from 'components/authors' +import Authors, { Author } from '@components/Authors'; # Introducing SWC 1.0 diff --git a/apps/website/docs/docs/_meta.json b/apps/website/docs/docs/_meta.json new file mode 100644 index 00000000..b44e8a07 --- /dev/null +++ b/apps/website/docs/docs/_meta.json @@ -0,0 +1,16 @@ +[ + "getting-started", + { "type": "dir", "name": "usage", "label": "Usage" }, + { "type": "dir", "name": "configuration", "label": "Configuration" }, + { "type": "dir", "name": "plugin", "label": "Plugin" }, + { "type": "dir", "name": "contributing", "label": "Contributing" }, + "team", + { "type": "file", "name": "roadmap", "label": "Roadmap" }, + "sponsors", + "customers", + "benchmarks", + { "type": "dir", "name": "references", "label": "API References" }, + "migrating-from-babel", + "migrating-from-tsc", + { "type": "file", "name": "swc-node-vs-swc", "label": "@swc-node vs @swc" } +] diff --git a/apps/website/content/docs/benchmarks.mdx b/apps/website/docs/docs/benchmarks.mdx similarity index 98% rename from apps/website/content/docs/benchmarks.mdx rename to apps/website/docs/docs/benchmarks.mdx index 23179add..e290c750 100644 --- a/apps/website/content/docs/benchmarks.mdx +++ b/apps/website/docs/docs/benchmarks.mdx @@ -1,4 +1,4 @@ -import Benchmark from 'components/benchmarks/dynamic' +import Benchmark from '@components/Benchmark'; # Benchmarks diff --git a/apps/website/docs/docs/configuration/_meta.json b/apps/website/docs/docs/configuration/_meta.json new file mode 100644 index 00000000..a67743b6 --- /dev/null +++ b/apps/website/docs/docs/configuration/_meta.json @@ -0,0 +1,8 @@ +[ + { "type": "file", "name": "swcrc", "label": ".swcrc" }, + "compilation", + "supported-browsers", + "modules", + "minification", + { "type": "file", "name": "bundling", "label": "Bundling" } +] diff --git a/apps/website/content/docs/configuration/bundling.mdx b/apps/website/docs/docs/configuration/bundling.mdx similarity index 93% rename from apps/website/content/docs/configuration/bundling.mdx rename to apps/website/docs/docs/configuration/bundling.mdx index c02662b6..490138c9 100644 --- a/apps/website/content/docs/configuration/bundling.mdx +++ b/apps/website/docs/docs/configuration/bundling.mdx @@ -1,4 +1,4 @@ -import { Callout } from 'nextra/components' +import Callout from '@components/Callout'; # Bundling Configuration @@ -19,7 +19,7 @@ View a [basic example of bundling](https://github.com/swc-project/pkgs/tree/main You can configure bundling using `spack.config.js` with similar options to webpack. In the future, we are exploring a webpack compatible plugin system. -```js filename="spack.config.js" copy +```js title="spack.config.js" module.exports = { entry: { @@ -35,7 +35,7 @@ module.exports = { If you want auto-completion or type checking for configuration, you can wrap the export with a `config` function from `@swc/core/spack`. It's an identity function with type annotation. -```ts filename="spack.config.js" copy +```ts title="spack.config.js" const { config } = require("@swc/core/spack"); module.exports = config({ @@ -66,7 +66,7 @@ Determines the entry of bundling. You may specify a file or a map of bundle name You can change destination directory of the bundler using `output`. -```ts filename="spack.config.js" copy +```ts title="spack.config.js" const { config } = require("@swc/core/spack"); module.exports = config({ diff --git a/apps/website/content/docs/configuration/compilation.mdx b/apps/website/docs/docs/configuration/compilation.mdx similarity index 94% rename from apps/website/content/docs/configuration/compilation.mdx rename to apps/website/docs/docs/configuration/compilation.mdx index c29bbce4..25379e43 100644 --- a/apps/website/content/docs/configuration/compilation.mdx +++ b/apps/website/docs/docs/configuration/compilation.mdx @@ -1,9 +1,9 @@ -import { Callout } from 'nextra/components' +import Callout from '@components/Callout'; SWC provides an official JSON Schema for the configuration file. -```json filename=".swcrc" copy +```json title=".swcrc" { "$schema": "https://swc.rs/schema.json", } @@ -15,7 +15,7 @@ SWC provides an official JSON Schema for the configuration file. Compilation works out of the box with SWC and does not require customization. Optionally, you can override the configuration. Here are the defaults: -```json filename=".swcrc" copy +```json title=".swcrc" { "jsc": { "parser": { @@ -63,7 +63,7 @@ Possible values: Example: -```json filename=".swcrc" copy +```json title=".swcrc" { "jsc": { "parser": { @@ -85,7 +85,7 @@ Example: Example of targeting `chrome 79`. -```json filename=".swcrc" copy +```json title=".swcrc" { "env": { "targets": { @@ -133,7 +133,7 @@ Feature or module to include. Example of enabling `async`/`yield` transform while targeting chrome 79. -```json filename=".swcrc" copy +```json title=".swcrc" { "env": { "targets": { @@ -159,7 +159,7 @@ Feature or module to exclude. Optional. Type: `string` -```json filename=".swcrc" copy +```json title=".swcrc" { "jsc": { "parser": { @@ -198,7 +198,7 @@ Enable bugfix passes. ## jsc.externalHelpers -```json filename=".swcrc" copy +```json title=".swcrc" { "jsc": { "externalHelpers": true @@ -229,7 +229,7 @@ Setting `"isModule": "unknown"` will make SWC infer the module type of each file ### typescript -```json filename=".swcrc" copy +```json title=".swcrc" { "jsc": { "parser": { @@ -244,7 +244,7 @@ Setting `"isModule": "unknown"` will make SWC infer the module type of each file ### flow -```json filename=".swcrc" copy +```json title=".swcrc" { "jsc": { "parser": { @@ -266,7 +266,7 @@ examples. ### ecmascript -```json filename=".swcrc" copy +```json title=".swcrc" { "jsc": { "parser": { @@ -290,7 +290,7 @@ examples. Starting from `@swc/core` v1.0.27, you can specify the target environment by using the field. -```json filename=".swcrc" copy +```json title=".swcrc" { "jsc": { // Disable es3 / es5 / es2015 transforms @@ -322,7 +322,7 @@ Starting from `@swc/core` v1.1.4, you can enable "loose" transformations by enab - [iterableIsArray](https://babeljs.io/docs/assumptions#iterableisarray) -```json filename=".swcrc" copy +```json title=".swcrc" { "jsc": { "loose": true @@ -332,7 +332,7 @@ Starting from `@swc/core` v1.1.4, you can enable "loose" transformations by enab ## jsc.transform -```json filename=".swcrc" copy +```json title=".swcrc" { "jsc": { "transform": { @@ -359,7 +359,7 @@ Starting from `@swc/core` v1.1.4, you can enable "loose" transformations by enab You can use the legacy (stage 1) class decorators syntax and behavior. -```json filename=".swcrc" copy +```json title=".swcrc" { "jsc": { "parser": { @@ -379,7 +379,7 @@ This feature requires `v1.2.13+`. If you are using typescript and decorators with `emitDecoratorMetadata` enabled, you can use `swc` for faster iteration: -```json filename=".swcrc" copy +```json title=".swcrc" { "jsc": { "parser": { @@ -405,7 +405,7 @@ Decides which runtime to use when transforming JSX. - Defaults to `'classic'`. - Use `runtime: 'automatic'` to use a JSX runtime module (e.g. `react/jsx-runtime` introduced in React 17). This is the modern approach introduced in React 17+ that eliminates the need to manually import React in every file that uses JSX. -```json filename=".swcrc" copy +```json title=".swcrc" { "jsc": { "transform": { @@ -419,7 +419,7 @@ Decides which runtime to use when transforming JSX. - Use `runtime: 'classic'` to use the traditional JSX transform that relies on `React.createElement` calls - with this option, you must ensure that `React` is in scope when using JSX. -```json filename=".swcrc" copy +```json title=".swcrc" { "jsc": { "transform": { @@ -433,7 +433,7 @@ Decides which runtime to use when transforming JSX. - Use `runtime: 'preserve'` to leave JSX syntax unchanged without transforming it. -```json filename=".swcrc" copy +```json title=".swcrc" { "jsc": { "transform": { @@ -475,7 +475,7 @@ Though the JSX spec allows this, it is disabled by default since React's JSX doe Toggles debug props `__self` and `__source` on elements generated from JSX, which are used by development tooling such as React Developer Tools. -This option is set automatically based on the Webpack `mode` setting when used with `swc-loader`. See [Using swc with webpack](/docs/usage-swc-loader/). +This option is set automatically based on the Webpack `mode` setting when used with `swc-loader`. See [Using swc with webpack](/docs/usage/swc-loader). #### jsc.transform.react.useBuiltins @@ -497,7 +497,7 @@ interface ReactRefreshConfig { ### jsc.transform.constModules -```json filename=".swcrc" copy +```json title=".swcrc" { "jsc": { "transform": { @@ -519,7 +519,7 @@ interface ReactRefreshConfig { Then, source code like: -```js filename="source.js" +```js title="source.js" import { DEBUG } from "@ember/env-flags"; import { FEATURE_A, FEATURE_B } from "@ember/features"; @@ -528,7 +528,7 @@ console.log(DEBUG, FEATURE_A, FEATURE_B); is transformed to: -```js filename="output.js" +```js title="output.js" console.log(true, false, true); ``` @@ -551,7 +551,7 @@ Setting this to `undefined` skips optimizer pass. You can set this to `false` to use `inline_globals` while skipping optimizations. -```json filename=".swcrc" copy +```json title=".swcrc" { "jsc": { "transform": { @@ -575,7 +575,7 @@ You can set this to `false` to use `inline_globals` while skipping optimizations - `vars` - Variables to inline. - `typeofs` - If you set `{ "window": "object" }`, `typeof window` will be replaced with `"object"`. -```json filename=".swcrc" copy +```json title=".swcrc" { "jsc": { "transform": { @@ -599,7 +599,7 @@ Then, you can use it like `npx swc '__DEBUG__' --filename input.js`. - `minCost` - If cost of parsing a pure object literal is larger than this value, the object literal is converted to `JSON.parse('{"foo": "bar"}')`. Defaults to 1024. -```json filename=".swcrc" copy +```json title=".swcrc" { "jsc": { "transform": { @@ -654,7 +654,7 @@ It follows resolving rule of node.js,. Specify the plugin name like -```json filename=".swcrc" copy +```json title=".swcrc" { "jsc": { "experimental": { @@ -674,7 +674,7 @@ Specify the location where SWC stores its intermediate cache files. Currently only transform plugin uses this. If not specified, SWC will create `.swc` directories. -```json filename=".swcrc" copy +```json title=".swcrc" { "jsc": { "experimental": { @@ -742,7 +742,7 @@ console.log(Foo.init); Starting from `v1.3.47`, you can use stage 3 decorator. -```json filename=".swcrc" copy +```json title=".swcrc" { "jsc": { "parser": { @@ -803,7 +803,7 @@ This makes SWC compile JavaScript files as CommonJS modules and compile TypeScri Note that `test` option can be used to transcompile only typescript files, like -```json filename=".swcrc" copy +```json title=".swcrc" { "test": ".*\\.ts$", "jsc": { @@ -821,7 +821,7 @@ Note that `test` option can be used to transcompile only typescript files, like Type: `Regex / Regex[]` -```json filename=".swcrc" copy +```json title=".swcrc" { "test": ".*\\.ts$", "jsc": { @@ -839,7 +839,7 @@ Type: `Regex / Regex[]` Type: `Regex / Regex[]` -```json filename=".swcrc" copy +```json title=".swcrc" { "exclude": [".*\\.js$", ".*\\.map$"], "jsc": { @@ -859,7 +859,7 @@ Type: `Regex / Regex[]` Enable source map by adding `sourceMaps: true` or `sourceMaps: 'inline'` to the `.swcrc`. -```json filename=".swcrc" copy +```json title=".swcrc" { "sourceMaps": true } @@ -871,7 +871,7 @@ Enable source map by adding `sourceMaps: true` or `sourceMaps: 'inline'` to the Defaults to `true`. If you want to make `swc` store contents of files into sourcemap, you can set `inlineSourcesContent` to `true`. -```json filename=".swcrc" copy +```json title=".swcrc" { "sourceMaps": true, "inlineSourcesContent": true diff --git a/apps/website/content/docs/configuration/minification.mdx b/apps/website/docs/docs/configuration/minification.mdx similarity index 93% rename from apps/website/content/docs/configuration/minification.mdx rename to apps/website/docs/docs/configuration/minification.mdx index bb2a22ab..ce65dcda 100644 --- a/apps/website/content/docs/configuration/minification.mdx +++ b/apps/website/docs/docs/configuration/minification.mdx @@ -1,13 +1,14 @@ -import { Callout } from 'nextra/components'; +import Callout from "@components/Callout"; # Minification This section is for people who want to use swc as a last step of the build process. If you want to use the swc minifier with a bundler, see the documentation for - - swcMinify with the Terser Webpack Plugin - - SWC Minify Webpack Plugin which is a - standalone tool if you only want minification. + +- [swcMinify with the Terser Webpack Plugin](https://webpack.js.org/plugins/terser-webpack-plugin/#swc) +- [SWC Minify Webpack Plugin](https://www.npmjs.com/package/swc-minify-webpack-plugin) which is a standalone tool if you only want minification. + # Assumptions @@ -58,7 +59,7 @@ Related: [terser - compiler assumptions](https://github.com/terser/terser#compil Starting with `v1.2.67`, you can configure SWC to minify your code by enabling `minify` in your `.swcrc` file: -```json filename=".swcrc" copy +```json title=".swcrc" { // Enable minification "minify": true, @@ -88,7 +89,7 @@ Type: `boolean | object`. Similar to [the compress option](https://terser.org/docs/options/#compress-options) of `terser`. -```json filename=".swcrc" copy +```json title=".swcrc" { "jsc": { "minify": { @@ -157,7 +158,7 @@ Type: `boolean | object`. Similar to [the mangle option](https://terser.org/docs/options/#mangle-options) of `terser`. -```json filename=".swcrc" copy +```json title=".swcrc" { "jsc": { "minify": { @@ -182,15 +183,15 @@ Type: `object`. Similar to [the mangle properties option](https://terser.org/docs/options/#mangle-properties-options) of `terser`. -```json filename=".swcrc" copy +```json title=".swcrc" { "jsc": { "minify": { - "mangle":{ - "properties":{ + "mangle": { + "properties": { "reserved": ["foo", "bar"], - "undeclared":false, - "regex":"rust regex" + "undeclared": false, + "regex": "rust regex" } } } @@ -267,7 +268,7 @@ const { code, map } = swc.minifySync( { compress: false, mangle: true, - module: true + module: true, } ); @@ -282,7 +283,7 @@ Returns `{ code: string, map: string }`. You can reduce build time and override Terser without needing a library to update their dependencies through [yarn resolutions](https://classic.yarnpkg.com/lang/en/docs/selective-version-resolutions/). Example `package.json` would include: -```json filename="package.json" +```json title="package.json" { "resolutions": { "terser": "npm:@swc/core" } } diff --git a/apps/website/content/docs/configuration/modules.mdx b/apps/website/docs/docs/configuration/modules.mdx similarity index 82% rename from apps/website/content/docs/configuration/modules.mdx rename to apps/website/docs/docs/configuration/modules.mdx index 7c9eba12..53ae5225 100644 --- a/apps/website/content/docs/configuration/modules.mdx +++ b/apps/website/docs/docs/configuration/modules.mdx @@ -1,9 +1,9 @@ -import { Callout } from 'nextra/components' +import Callout from '@components/Callout'; SWC provides an official JSON Schema for the configuration file. -```json filename=".swcrc" copy +```json title=".swcrc" { "$schema": "https://swc.rs/schema.json", } @@ -19,7 +19,7 @@ SWC can transpile your code using ES Modules to CommonJS or UMD/AMD. By default, To emit a CommonJS module, change the `type` in `.swcrc`: -```json filename=".swcrc" copy +```json title=".swcrc" { "$schema": "https://swc.rs/schema.json", "module": { @@ -38,7 +38,7 @@ To emit a CommonJS module, change the `type` in `.swcrc`: To emit a ES6 module, change the `type` in `.swcrc`: -```json filename=".swcrc" copy +```json title=".swcrc" { "module": { "type": "es6", @@ -56,7 +56,7 @@ To emit a ES6 module, change the `type` in `.swcrc`: To emit an AMD module, change the `type` in `.swcrc`: -```json filename=".swcrc" copy +```json title=".swcrc" { "module": { "type": "amd", @@ -76,7 +76,7 @@ To emit an AMD module, change the `type` in `.swcrc`: To emit an UMD module, change the `type` in `.swcrc`: -```json filename=".swcrc" copy +```json title=".swcrc" { "module": { "type": "umd", @@ -95,7 +95,7 @@ To emit an UMD module, change the `type` in `.swcrc`: These options are shared by `commonjs` / `es6` / `umd` / `amd` inside `.swcrc`: -```json filename=".swcrc" copy +```json title=".swcrc" { "module": { // You can specify "commonjs", "es6", "amd", "umd" @@ -111,14 +111,11 @@ These options are shared by `commonjs` / `es6` / `umd` / `amd` inside `.swcrc`: } ``` -{/* TODO: should fix this in nextra side */} -export const EsModuleText = () => {`__esModule`} - ### strict -Defaults to `false`. By default, when using exports with SWC, a non-enumerable property is exported. In some cases, this property is used to determine if the import is the default export or if it contains the default export. +Defaults to `false`. By default, when using exports with SWC, a non-enumerable `__esModule` property is exported. In some cases, this property is used to determine if the import is the default export or if it contains the default export. -To prevent the property from being exported, you can set the strict option to `true`. +To prevent the `__esModule` property from being exported, you can set the strict option to `true`. ### strictMode @@ -144,7 +141,7 @@ The two cases where imports can never be lazy are: ### noInterop -Defaults to `false`. By default, when using exports with swc a non-enumerable property is exported. +Defaults to `false`. By default, when using exports with swc a non-enumerable `__esModule` property is exported. This property is then used to determine if the import is the default export or if it contains the default export. In cases where the auto-unwrapping of default is not needed, you can set the noInterop option to true to avoid the usage of the interopRequireDefault helper (shown in inline form above). diff --git a/apps/website/content/docs/configuration/supported-browsers.mdx b/apps/website/docs/docs/configuration/supported-browsers.mdx similarity index 94% rename from apps/website/content/docs/configuration/supported-browsers.mdx rename to apps/website/docs/docs/configuration/supported-browsers.mdx index e8b26d1e..ee889ecc 100644 --- a/apps/website/content/docs/configuration/supported-browsers.mdx +++ b/apps/website/docs/docs/configuration/supported-browsers.mdx @@ -1,4 +1,4 @@ -import { Callout } from 'nextra/components' +import Callout from '@components/Callout'; # Supported Browsers @@ -6,7 +6,7 @@ Starting with `v1.1.10`, you can now use `browserslist` to automatically configu ## Usage -```json filename=".swcrc" copy +```json title=".swcrc" { "env": { "targets": { @@ -26,7 +26,7 @@ Starting with `v1.1.10`, you can now use `browserslist` to automatically configu Describes the environments you support/target for your project. This can either be a [browserslist-compatible](https://github.com/ai/browserslist) query [(with limitations)](https://github.com/browserslist/browserslist-rs#limitations): -```json filename=".swcrc" copy +```json title=".swcrc" { "env": { "targets": "> 0.25%, not dead" @@ -36,7 +36,7 @@ Describes the environments you support/target for your project. This can either Or an object of minimum environment versions to support: -```json filename=".swcrc" copy +```json title=".swcrc" { "env": { "targets": { @@ -81,7 +81,7 @@ If `targets` is not specified, SWC uses `browserslist` to get target information Define ES features to skip to reduce bundle size. For example, your `.swcrc` could be: -```json filename=".swcrc" copy +```json title=".swcrc" { "env": { "skip": ["core-js/modules/foo"] diff --git a/apps/website/content/docs/configuration/swcrc.mdx b/apps/website/docs/docs/configuration/swcrc.mdx similarity index 91% rename from apps/website/content/docs/configuration/swcrc.mdx rename to apps/website/docs/docs/configuration/swcrc.mdx index 7c781640..9260e296 100644 --- a/apps/website/content/docs/configuration/swcrc.mdx +++ b/apps/website/docs/docs/configuration/swcrc.mdx @@ -1,9 +1,9 @@ -import { Callout } from 'nextra/components' +import Callout from '@components/Callout'; SWC provides an official JSON Schema for the configuration file. -```json filename=".swcrc" copy +```json title=".swcrc" { "$schema": "https://swc.rs/schema.json", } @@ -19,7 +19,7 @@ SWC can be configured with an `.swcrc` file. Compilation works out of the box with SWC and does not require customization. Optionally, you can override the configuration. Here are the defaults: -```jsonc filename=".swcrc" copy +```jsonc title=".swcrc" { "$schema": "https://swc.rs/schema.json", "jsc": { @@ -57,7 +57,7 @@ Starting with `v1.1.10`, you can now use `browserslist` to automatically configu First, install `browserslist`. Then, update your `.swcrc`: -```json filename=".swcrc" copy +```json title=".swcrc" { "env": { "targets": { @@ -79,7 +79,7 @@ Read more about [configuring modules](/docs/configuration/modules). Starting with `v1.2.67`, you can configure SWC to minify your code by enabling `minify` in your `.swcrc` file: -```json filename=".swcrc" copy +```json title=".swcrc" { "minify": true } diff --git a/apps/website/docs/docs/contributing/_meta.json b/apps/website/docs/docs/contributing/_meta.json new file mode 100644 index 00000000..c49f617f --- /dev/null +++ b/apps/website/docs/docs/contributing/_meta.json @@ -0,0 +1,5 @@ +[ + { "type": "dir", "name": "commons", "label": "Commons" }, + { "type": "dir", "name": "es-commons", "label": "ECMAScript Commons" }, + { "type": "dir", "name": "es-minifier", "label": "ECMAScript Minifier" } +] diff --git a/apps/website/docs/docs/contributing/commons/_meta.json b/apps/website/docs/docs/contributing/commons/_meta.json new file mode 100644 index 00000000..59ef7e24 --- /dev/null +++ b/apps/website/docs/docs/contributing/commons/_meta.json @@ -0,0 +1 @@ +[{ "type": "file", "name": "string-management", "label": "String Management" }] diff --git a/apps/website/content/docs/contributing/commons/string-management.mdx b/apps/website/docs/docs/contributing/commons/string-management.mdx similarity index 95% rename from apps/website/content/docs/contributing/commons/string-management.mdx rename to apps/website/docs/docs/contributing/commons/string-management.mdx index ba262284..81e7e169 100644 --- a/apps/website/content/docs/contributing/commons/string-management.mdx +++ b/apps/website/docs/docs/contributing/commons/string-management.mdx @@ -1,3 +1,7 @@ +--- +title: String Management +--- + ## String Interning See [`hstr`][] for more details. diff --git a/apps/website/docs/docs/contributing/es-commons/_meta.json b/apps/website/docs/docs/contributing/es-commons/_meta.json new file mode 100644 index 00000000..3b96408b --- /dev/null +++ b/apps/website/docs/docs/contributing/es-commons/_meta.json @@ -0,0 +1 @@ +["variable-management"] diff --git a/apps/website/content/docs/contributing/es-commons/variable-management.mdx b/apps/website/docs/docs/contributing/es-commons/variable-management.mdx similarity index 100% rename from apps/website/content/docs/contributing/es-commons/variable-management.mdx rename to apps/website/docs/docs/contributing/es-commons/variable-management.mdx diff --git a/apps/website/docs/docs/contributing/es-minifier/_meta.json b/apps/website/docs/docs/contributing/es-minifier/_meta.json new file mode 100644 index 00000000..264fb3e8 --- /dev/null +++ b/apps/website/docs/docs/contributing/es-minifier/_meta.json @@ -0,0 +1,9 @@ +[ + { "type": "file", "name": "profiling", "label": "Profiling" }, + { + "type": "file", + "name": "debugging-nextjs-app", + "label": "Debugging Next.js App" + }, + { "type": "file", "name": "debugging-size", "label": "Debugging Size" } +] diff --git a/apps/website/content/docs/contributing/es-minifier/debugging-nextjs-app.mdx b/apps/website/docs/docs/contributing/es-minifier/debugging-nextjs-app.mdx similarity index 96% rename from apps/website/content/docs/contributing/es-minifier/debugging-nextjs-app.mdx rename to apps/website/docs/docs/contributing/es-minifier/debugging-nextjs-app.mdx index 32843860..dfa87a9d 100644 --- a/apps/website/content/docs/contributing/es-minifier/debugging-nextjs-app.mdx +++ b/apps/website/docs/docs/contributing/es-minifier/debugging-nextjs-app.mdx @@ -1,3 +1,7 @@ +--- +title: Debugging Next.js App +--- + ## Steps to extract the inputs to the SWC minifier. ### Step 1. Clone the SWC repository diff --git a/apps/website/content/docs/contributing/es-minifier/debugging-size.mdx b/apps/website/docs/docs/contributing/es-minifier/debugging-size.mdx similarity index 100% rename from apps/website/content/docs/contributing/es-minifier/debugging-size.mdx rename to apps/website/docs/docs/contributing/es-minifier/debugging-size.mdx diff --git a/apps/website/content/docs/contributing/es-minifier/profiling.mdx b/apps/website/docs/docs/contributing/es-minifier/profiling.mdx similarity index 100% rename from apps/website/content/docs/contributing/es-minifier/profiling.mdx rename to apps/website/docs/docs/contributing/es-minifier/profiling.mdx diff --git a/apps/website/content/docs/customers.mdx b/apps/website/docs/docs/customers.mdx similarity index 52% rename from apps/website/content/docs/customers.mdx rename to apps/website/docs/docs/customers.mdx index c5a1ddc9..8428952c 100644 --- a/apps/website/content/docs/customers.mdx +++ b/apps/website/docs/docs/customers.mdx @@ -1,4 +1,4 @@ -import Customers from "../../components/Customers"; +import Customers from '@components/Customers'; # Customers diff --git a/apps/website/content/docs/getting-started.mdx b/apps/website/docs/docs/getting-started.mdx similarity index 78% rename from apps/website/content/docs/getting-started.mdx rename to apps/website/docs/docs/getting-started.mdx index 69ef4a50..f8933a6b 100644 --- a/apps/website/content/docs/getting-started.mdx +++ b/apps/website/docs/docs/getting-started.mdx @@ -1,30 +1,29 @@ -import { Callout, Tabs, Tab } from 'nextra/components' -import Link from 'next/link' +import { Tab, Tabs } from '@rspress/core/theme'; # Getting Started ## Installation -The easiest way to try SWC is using the [Playground](/playground). +The easiest way to try SWC is using the [Playground](/playground/). Otherwise, run the following to download pre-built binaries: - - + + ```bash pnpm add -D @swc/cli @swc/core ``` - - +
+ ```bash npm i -D @swc/cli @swc/core ``` -
- + + ```bash yarn add -D @swc/cli @swc/core ``` - +
Then, you can transpile your first file and emit to `stdout`: diff --git a/apps/website/content/docs/migrating-from-babel.md b/apps/website/docs/docs/migrating-from-babel.md similarity index 100% rename from apps/website/content/docs/migrating-from-babel.md rename to apps/website/docs/docs/migrating-from-babel.md diff --git a/apps/website/content/docs/migrating-from-tsc.md b/apps/website/docs/docs/migrating-from-tsc.md similarity index 100% rename from apps/website/content/docs/migrating-from-tsc.md rename to apps/website/docs/docs/migrating-from-tsc.md diff --git a/apps/website/docs/docs/plugin/_meta.json b/apps/website/docs/docs/plugin/_meta.json new file mode 100644 index 00000000..eee81e88 --- /dev/null +++ b/apps/website/docs/docs/plugin/_meta.json @@ -0,0 +1,14 @@ +[ + { + "type": "file", + "name": "selecting-swc-core", + "label": "Selecting swc_core" + }, + { "type": "dir", "name": "ecmascript", "label": "ECMAScript" }, + { "type": "file", "name": "publishing", "label": "Publishing" }, + { + "type": "file", + "name": "registering-plugins", + "label": "Registering Plugins" + } +] diff --git a/apps/website/docs/docs/plugin/ecmascript/_meta.json b/apps/website/docs/docs/plugin/ecmascript/_meta.json new file mode 100644 index 00000000..f7d2dfe2 --- /dev/null +++ b/apps/website/docs/docs/plugin/ecmascript/_meta.json @@ -0,0 +1,5 @@ +[ + { "type": "file", "name": "getting-started", "label": "Getting started" }, + { "type": "file", "name": "cheatsheet", "label": "Cheatsheet" }, + { "type": "file", "name": "compatibility", "label": "Compatibility" } +] diff --git a/apps/website/content/docs/plugin/ecmascript/cheatsheet.mdx b/apps/website/docs/docs/plugin/ecmascript/cheatsheet.mdx similarity index 99% rename from apps/website/content/docs/plugin/ecmascript/cheatsheet.mdx rename to apps/website/docs/docs/plugin/ecmascript/cheatsheet.mdx index e5e4a9fb..6d2806a7 100644 --- a/apps/website/content/docs/plugin/ecmascript/cheatsheet.mdx +++ b/apps/website/docs/docs/plugin/ecmascript/cheatsheet.mdx @@ -1,4 +1,4 @@ -import { Callout } from 'nextra/components'; +import Callout from '@components/Callout'; # Plugin cheatsheet @@ -200,7 +200,7 @@ instead. You can test your transform with `@swc/jest` by adding your plugin to your `jest.config.js`. -```js filename="jest.config.js" +```js title="jest.config.js" module.exports = { rootDir: __dirname, moduleNameMapper: { diff --git a/apps/website/content/docs/plugin/ecmascript/compatibility.mdx b/apps/website/docs/docs/plugin/ecmascript/compatibility.mdx similarity index 100% rename from apps/website/content/docs/plugin/ecmascript/compatibility.mdx rename to apps/website/docs/docs/plugin/ecmascript/compatibility.mdx diff --git a/apps/website/content/docs/plugin/ecmascript/compatibility/overview.png b/apps/website/docs/docs/plugin/ecmascript/compatibility/overview.png similarity index 100% rename from apps/website/content/docs/plugin/ecmascript/compatibility/overview.png rename to apps/website/docs/docs/plugin/ecmascript/compatibility/overview.png diff --git a/apps/website/content/docs/plugin/ecmascript/getting-started.mdx b/apps/website/docs/docs/plugin/ecmascript/getting-started.mdx similarity index 99% rename from apps/website/content/docs/plugin/ecmascript/getting-started.mdx rename to apps/website/docs/docs/plugin/ecmascript/getting-started.mdx index b548d781..54633ffb 100644 --- a/apps/website/content/docs/plugin/ecmascript/getting-started.mdx +++ b/apps/website/docs/docs/plugin/ecmascript/getting-started.mdx @@ -1,4 +1,4 @@ -import { Callout } from 'nextra/components' +import Callout from '@components/Callout'; # Implementing a plugin diff --git a/apps/website/content/docs/plugin/publishing.mdx b/apps/website/docs/docs/plugin/publishing.mdx similarity index 96% rename from apps/website/content/docs/plugin/publishing.mdx rename to apps/website/docs/docs/plugin/publishing.mdx index 47f36db9..c3d94ed6 100644 --- a/apps/website/content/docs/plugin/publishing.mdx +++ b/apps/website/docs/docs/plugin/publishing.mdx @@ -25,7 +25,7 @@ It will create `target/wasm32-wasi/release/your_plugin_name.wasm` or `target/was Add the following to your `package.json`: -```json filename="package.json" +```json title="package.json" { "main": "your_plugin_name.wasm", "scripts": { @@ -42,7 +42,7 @@ You can reduce the size of the plugin by configuring cargo. In your `Cargo.toml` file, you can add the following lines. -```toml filename="Cargo.toml" +```toml title="Cargo.toml" [profile.release] # This removes more dead code codegen-units = 1 diff --git a/apps/website/content/docs/plugin/registering-plugins.mdx b/apps/website/docs/docs/plugin/registering-plugins.mdx similarity index 100% rename from apps/website/content/docs/plugin/registering-plugins.mdx rename to apps/website/docs/docs/plugin/registering-plugins.mdx diff --git a/apps/website/content/docs/plugin/selecting-swc-core.mdx b/apps/website/docs/docs/plugin/selecting-swc-core.mdx similarity index 100% rename from apps/website/content/docs/plugin/selecting-swc-core.mdx rename to apps/website/docs/docs/plugin/selecting-swc-core.mdx diff --git a/apps/website/docs/docs/references/_meta.json b/apps/website/docs/docs/references/_meta.json new file mode 100644 index 00000000..57846b4b --- /dev/null +++ b/apps/website/docs/docs/references/_meta.json @@ -0,0 +1 @@ +["wasm-typescript"] diff --git a/apps/website/content/docs/references/wasm-typescript.mdx b/apps/website/docs/docs/references/wasm-typescript.mdx similarity index 97% rename from apps/website/content/docs/references/wasm-typescript.mdx rename to apps/website/docs/docs/references/wasm-typescript.mdx index bc0c34be..84edfd13 100644 --- a/apps/website/content/docs/references/wasm-typescript.mdx +++ b/apps/website/docs/docs/references/wasm-typescript.mdx @@ -8,7 +8,7 @@ npm install @swc/wasm-typescript ### Usage -```typescript +```ts twoslash import { transform } from '@swc/wasm-typescript'; const tsSourceCode = ` diff --git a/apps/website/content/docs/roadmap.md b/apps/website/docs/docs/roadmap.md similarity index 100% rename from apps/website/content/docs/roadmap.md rename to apps/website/docs/docs/roadmap.md diff --git a/apps/website/content/docs/sponsors.mdx b/apps/website/docs/docs/sponsors.mdx similarity index 100% rename from apps/website/content/docs/sponsors.mdx rename to apps/website/docs/docs/sponsors.mdx diff --git a/apps/website/content/docs/swc-node-vs-swc.md b/apps/website/docs/docs/swc-node-vs-swc.md similarity index 100% rename from apps/website/content/docs/swc-node-vs-swc.md rename to apps/website/docs/docs/swc-node-vs-swc.md diff --git a/apps/website/content/docs/team.mdx b/apps/website/docs/docs/team.mdx similarity index 53% rename from apps/website/content/docs/team.mdx rename to apps/website/docs/docs/team.mdx index 78fdb069..e8b09396 100644 --- a/apps/website/content/docs/team.mdx +++ b/apps/website/docs/docs/team.mdx @@ -1,4 +1,4 @@ -import TeamMembers from "../../components/TeamMembers"; +import TeamMembers from '@components/TeamMembers'; # The Team diff --git a/apps/website/docs/docs/usage/_meta.json b/apps/website/docs/docs/usage/_meta.json new file mode 100644 index 00000000..8ef60a74 --- /dev/null +++ b/apps/website/docs/docs/usage/_meta.json @@ -0,0 +1,10 @@ +[ + "cli", + "core", + "flow", + { "type": "file", "name": "wasm", "label": "@swc/wasm" }, + "jest", + "swc-loader", + { "type": "file", "name": "html", "label": "@swc/html" }, + { "type": "file", "name": "bundling", "label": "Bundling" } +] diff --git a/apps/website/content/docs/usage/bundling.mdx b/apps/website/docs/docs/usage/bundling.mdx similarity index 87% rename from apps/website/content/docs/usage/bundling.mdx rename to apps/website/docs/docs/usage/bundling.mdx index b82e4cf8..5025b661 100644 --- a/apps/website/content/docs/usage/bundling.mdx +++ b/apps/website/docs/docs/usage/bundling.mdx @@ -1,4 +1,5 @@ -import { Callout, Tab, Tabs } from 'nextra/components' +import { Tab, Tabs } from '@rspress/core/theme'; +import Callout from '@components/Callout'; # Bundling (swcpack) @@ -17,22 +18,22 @@ View a [basic example of bundling](https://github.com/swc-project/pkgs/tree/main ## Usage - - - ```bash copy - pnpm i -D @swc/cli @swc/core + + + ```bash + pnpm add -D @swc/cli @swc/core ``` - - - ```bash copy + + + ```bash npm i -D @swc/cli @swc/core ``` - - - ```bash copy + + + ```bash yarn add -D @swc/cli @swc/core ``` - + Create a `spack.config.js` file and run: @@ -51,21 +52,21 @@ To see all options, [view the configuration](/docs/configuration/bundling). Just like `rollup`, SWC emits compact output. -```js filename="a.js" +```js title="a.js" console.log("loading A"); export function a() { console.log("use!"); } ``` -```js filename="lib.js" +```js title="lib.js" import { a } from "./a"; a(); ``` becomes: -```js filename="output.js" +```js title="output.js" console.log("loading A"); function a() { console.log("use!"); @@ -101,14 +102,14 @@ This preserves all side effects. SWC supports importing CommonJS modules and emits more compact output than webpack. -```js filename="source.js" +```js title="source.js" import * as lib from "lib"; console.log(lib); // Prevent dce ``` If the `lib` above is a CommonJS module, it's transcompiled to: -```js filename="output.js" +```js title="output.js" const load = __spack_require.bind(void 0, function (module, exports) { // Code from lib goes here }); @@ -125,7 +126,7 @@ console.log(lib); // Prevent dce The tree shaking described above is using the dead code elimination pass. Currently, SWC can deduce: -```js filename="source.js" +```js title="source.js" let b = 2; let a = 1; if (b) { @@ -140,7 +141,7 @@ console.log(c); into: -```js filename="output.js" +```js title="output.js" console.log(3); ``` @@ -150,7 +151,7 @@ Performance is a priority for SWC. It's very fast because it uses all CPU cores ### Multiple Entries Support -```js filename="spack.config.js" +```js title="spack.config.js" const { config } = require("@swc/core/spack"); module.exports = config({ diff --git a/apps/website/content/docs/usage/cli.mdx b/apps/website/docs/docs/usage/cli.mdx similarity index 93% rename from apps/website/content/docs/usage/cli.mdx rename to apps/website/docs/docs/usage/cli.mdx index a17419e9..53bf20cf 100644 --- a/apps/website/content/docs/usage/cli.mdx +++ b/apps/website/docs/docs/usage/cli.mdx @@ -1,4 +1,4 @@ -import { Callout, Tabs, Tab } from 'nextra/components' +import { Tab, Tabs } from '@rspress/core/theme'; # @swc/cli @@ -6,22 +6,22 @@ import { Callout, Tabs, Tab } from 'nextra/components' Run the following to download pre-built binaries: - - - ```bash copy - pnpm i -D @swc/cli @swc/core + + + ```bash + pnpm add -D @swc/cli @swc/core ``` - - - ```bash copy + + + ```bash npm i -D @swc/cli @swc/core ``` - - - ```bash copy + + + ```bash yarn add -D @swc/cli @swc/core ``` - + Then, you can transpile your files: @@ -42,7 +42,7 @@ npx swc ./my-dir -d output To compile Flow code with the CLI, point `swc` at a `.swcrc` file that sets `jsc.parser.syntax` to `"flow"`: -```json filename=".swcrc" copy +```json title=".swcrc" { "jsc": { "parser": { @@ -52,7 +52,7 @@ To compile Flow code with the CLI, point `swc` at a `.swcrc` file that sets } ``` -```sh copy +```sh npx swc input.js --config-file .swcrc -o output.js ``` diff --git a/apps/website/content/docs/usage/core.mdx b/apps/website/docs/docs/usage/core.mdx similarity index 98% rename from apps/website/content/docs/usage/core.mdx rename to apps/website/docs/docs/usage/core.mdx index 2743891d..25b4314d 100644 --- a/apps/website/content/docs/usage/core.mdx +++ b/apps/website/docs/docs/usage/core.mdx @@ -1,4 +1,4 @@ -import TypeDeclarations from 'components/TypeDeclarations' +import TypeDeclarations from '@components/TypeDeclarations'; # @swc/core @@ -8,8 +8,8 @@ These are the core SWC APIs mainly useful for build tool authors. `@swc/core` provides appropriate `.d.ts` file, so you may not need this. Returns `Promise<{ code: string, map?: string }>` -```js copy -const swc = require("@swc/core"); +```ts twoslash +import * as swc from "@swc/core"; swc .transform("source code", { @@ -38,8 +38,8 @@ swc To transform Flow code, set `jsc.parser.syntax` to `"flow"`. SWC will parse Flow syntax and strip type-only constructs as part of the transform pipeline. -```js copy -const swc = require("@swc/core"); +```ts twoslash +import * as swc from "@swc/core"; swc.transform("const value: number = 1;", { jsc: { @@ -68,8 +68,8 @@ Returns `{ code: string, map?: string }` Returns `Promise