Skip to content

ut-code/utcode-learn-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

ut.code(); Learn準拠サンプルプロジェクト

ut.code(); Learnに準拠したサンプルプロジェクトです。

要点

開発環境と本番環境での差異を意識する必要があります。

  • フロントエンド
    • 開発環境:Viteの開発用サーバー
    • 本番環境:Viteにより出力されたHTML・CSS・JavaScriptファイル群
  • バックエンド
    • 開発環境:今回はtsxを使用(トランスパイルをしつつ実行できる)
    • 本番環境:TypeScriptのトランスパイラ(tsc)により出力されたJavaScriptファイル群

このリポジトリを作成した手順

  1. 次のとおりに実行する

    $ 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
  2. /frontend/.envを作成して、VITE_API_ENDPOINThttp://localhost:3000に設定する

  3. /backend/.envWEB_ORIGINhttp://localhost:5173に設定し、DATABASE_URLも設定する

  4. /backend/prisma/schema.prismaの内容をデータベースに反映させるためにnpx prisma db pushを実行する

  5. /backend/tsconfig.jsonoutDirオプションを./distにしてトランスパイル結果が/backend/distに入るようにする

  6. /backend/tsconfig.jsonallowJsオプションをtrueにしてPrismaが生成したJavaScriptファイルをトランスパイル結果に含めるようにする

  7. /backend/dist/backend/.gitignoreに追加する

  8. /backend/package.jsonを変更して次のコマンドが使えるようにする

    • npm run devtsxを使ってトランスパイル前のTypeScriptを直接実行する(開発環境用)
    • npm run buildtscを使ってTypeScriptをJavaScriptにトランスパイルする
    • npm starttscによって出力された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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •