@k8ordo/framework
同じ書き方のまま、サーバーなしかサーバーありかを選べるReact Server Componentsのフレームワーク
npm
yarn
pnpm
npm install -D @k8ordo/framework @k8ordo/routervite.config.tsimport { framework } from '@k8ordo/framework/vite';
import { defineConfig } from 'vite';
export default defineConfig({
plugins: [framework({ mode: 'static' })],
});src/routes/products/page.tsxexport default function ProductsPage() {
return <h1>Products</h1>;
}vite builddist/client/
products/index.htmlディレクトリ構成で決まるURL
src/routes/の下のディレクトリがURLの階層になり、page.tsxがそのURLのページになります。[id]はパラメータです。
ほかのルートが先に一致して表示されないページや、同じURLになるファイルが2つあると、ビルドできません。エラーにはファイル名が出ます。
src/routes/
layout.tsx
page.tsx
not-found.tsx
products/
page.tsx
[id]/page.tsxアプリごとに選ぶ2つのモード
mode: 'static'はページをビルド時に描画し、サーバーなしで静的ホスティングに置けるアプリにします。mode: 'server'はリクエストごとにサーバーで描画し、Server ActionやCookieも使えるアプリにします。
ページやレイアウトの書き方は、どちらのモードでも同じです。
vite.config.tsframework({ mode: 'static' });Terminalvite buildvite.config.tsframework({ mode: 'server' });Terminalvite build
node dist/server.js