ut.code(); Learnに準拠したサンプルプロジェクトです。
開発環境と本番環境での差異を意識する必要があります。
- フロントエンド
- 開発環境:Viteの開発用サーバー
- 本番環境:Viteにより出力されたHTML・CSS・JavaScriptファイル群
- バックエンド
- 開発環境:今回は
tsx
を使用(トランスパイルをしつつ実行できる) - 本番環境:TypeScriptのトランスパイラ(
tsc
)により出力されたJavaScriptファイル群
- 開発環境:今回は
-
次のとおりに実行する
$ npm create vite@latest > npx > create-vite │ ◇ Project name: │ frontend │ ◇ Select a framework: │ React │ ◇ Select a variant: │ TypeScript │ ◇ Scaffolding project in /home/user/projects/utcode-learn-template/frontend... │ └ Done. Now run: cd frontend npm install npm run dev $ cd frontend $ npm install $ cd .. $ mkdir backend $ cd backend $ npm init $ npm install express cors $ npm install -D typescript tsx @types/express @types/cors $ npx tsc --init $ npx prisma init
-
/frontend/.env
を作成して、VITE_API_ENDPOINT
をhttp://localhost:3000
に設定する -
/backend/.env
でWEB_ORIGIN
をhttp://localhost:5173
に設定し、DATABASE_URL
も設定する -
/backend/prisma/schema.prisma
の内容をデータベースに反映させるためにnpx prisma db push
を実行する -
/backend/tsconfig.json
のoutDir
オプションを./dist
にしてトランスパイル結果が/backend/dist
に入るようにする -
/backend/tsconfig.json
のallowJs
オプションをtrue
にしてPrismaが生成したJavaScriptファイルをトランスパイル結果に含めるようにする -
/backend/dist
を/backend/.gitignore
に追加する -
/backend/package.json
を変更して次のコマンドが使えるようにするnpm run dev
:tsx
を使ってトランスパイル前のTypeScriptを直接実行する(開発環境用)npm run build
:tsc
を使ってTypeScriptをJavaScriptにトランスパイルするnpm start
:tsc
によって出力されたJavaScriptを実行する(本番環境用)
- Expressの起動:
cd backend && npm run dev
- Viteの開発用サーバーの起動:
cd frontend && npm run dev
このリポジトリの内容は、基本的に自由にご利用いただけます。ただし、利用条件を明確にするため、以下のとおりMITライセンスを適用しています。
MIT License
Copyright (c) 2025 ut.code();
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.