-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: 開発モードでフロントエンドとバックエンドを独立して起動するようにする #12452
chore: 開発モードでフロントエンドとバックエンドを独立して起動するようにする #12452
Conversation
cssの読み込み順序とCSP設定の変更
設定画面からUI言語を変更したらブラックアウトする
This reverts commit 582601e. # Conflicts: # packages/frontend/vite.config.ts
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #12452 +/- ##
===========================================
- Coverage 78.93% 78.83% -0.10%
===========================================
Files 957 958 +1
Lines 104165 104229 +64
Branches 8361 8331 -30
===========================================
- Hits 82218 82171 -47
- Misses 21947 22058 +111 ☔ View full report in Codecov by Sentry. |
.config/dev-local.yml
Outdated
|
||
# Final accessible URL seen by a user. | ||
# dev-local では identiconのCORS問題の解決のため 127.0.0.1 である必要があります | ||
url: http://127.0.0.1:5173/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
このファイルの主な違いはここだけです
docker-compose.local-dev.yml
Outdated
@@ -0,0 +1,42 @@ | |||
version: "3" | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
このファイルでは redisとpostgresのみを起動するために作りました。
webのサービスが消え、そのdependencyがなくなり、ホストマシンからアクセスできるように portsが加えられています。
@@ -26,7 +26,7 @@ | |||
"check:connect": "cd packages/backend && pnpm check:connect", | |||
"migrateandstart": "pnpm migrate && pnpm start", | |||
"watch": "pnpm dev", | |||
"dev": "node ./scripts/dev.mjs", | |||
"dev": "pnpm -r dev", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dev.mjsのかわりに pnpm -r dev をしています。
dev.mjsは削除してもよいかもしれません(このPRでは行っていません)
} else { | ||
if (defaultStore.state.darkMode) { | ||
applyTheme(darkTheme.value); | ||
} else { | ||
applyTheme(lightTheme.value); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
local-devモードでテーマがapplyされないことの修正です
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
↑の旨をコメントに残しておくと良さそう
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
自由に付け足したりしておいていただけると
@@ -260,6 +260,7 @@ const useGroupedNotifications = computed(defaultStore.makeGetterSetter('useGroup | |||
watch(lang, () => { | |||
miLocalStorage.setItem('lang', lang.value as string); | |||
miLocalStorage.removeItem('locale'); | |||
miLocalStorage.removeItem('localeVersion'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
言語を変更したときに local-devモードで色々おかしくなる問題の対応です。
fruitriin#3
@@ -0,0 +1,187 @@ | |||
import path from 'path'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
local-devモードのvite.configです。 通常用のvite.config.tsの差分として作ってもよかったのですが、今回はスコープアウトしました
host: '127.0.0.1', | ||
port: 5173, | ||
proxy: { | ||
'/api': { | ||
changeOrigin: true, | ||
target: 'http://127.0.0.1:3000/', | ||
}, | ||
'/assets': 'http://127.0.0.1:3000/', | ||
'/files': 'http://127.0.0.1:3000/', | ||
'/twemoji': 'http://127.0.0.1:3000/', | ||
'/fluent-emoji': 'http://127.0.0.1:3000/', | ||
'/sw.js': 'http://127.0.0.1:3000/', | ||
'/streaming': { | ||
target: 'ws://127.0.0.1:3000/', | ||
ws: true, | ||
}, | ||
'/favicon.ico': 'http://127.0.0.1:3000/', | ||
'/identicon': { | ||
target: 'http://127.0.0.1:3000/', | ||
rewrite(path) { | ||
return path.replace('@127.0.0.1:5173', ''); | ||
}, | ||
|
||
}, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
主な変更点です。
これにより、フロントエンドへのリクエストの一部をバックエンドにプロキシするなどを行っています。
'safari16', | ||
], | ||
manifest: 'manifest.json', | ||
rollupOptions: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rollupOptionsのinputを削除しています。
この場合、index.htmlが対象となります。
このPRによるapi.jsonの差分 差分はこちら |
…lone-frontend # Conflicts: # packages/frontend/src/pages/welcome.entrance.a.vue
…lone-frontend # Conflicts: # packages/frontend/src/pages/welcome.entrance.a.vue
…lone-frontend # Conflicts: # packages/frontend/src/pages/welcome.entrance.a.vue
@@ -4,6 +4,7 @@ | |||
"type": "module", | |||
"scripts": { | |||
"watch": "vite", | |||
"dev": "vite --config vite.config.local-dev.ts", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
devでは vite.config.ts のかわりに vite.config.local-dev.tsを使用します。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2点ほどコメントしました
@syuilo これでどうだ! |
最近私は開発に参加してないし割と根本的な話なので無視してもらって構わないのだけれど、個人的にviteでプロキシする挙動はあんまり好きではないです…
これを解消する方向の方がいいと思う |
プロクシする挙動になってるのはフロントエンドとバックエンドのドメイン(ホスト名+ポート名)が同じものとして認識してくれないとCORSによって各種リクエストが拒絶されてしまうからです
どちらが望ましいですか? |
番号を教えてください:pray: |
これ |
#10894 の理解に相違がありそうというのは一旦置いておいて、フロント開発するのにわざわざバックエンドを動かしておきたくないよね(つまり既存のサーバーにつなげたい)というのはわかる |
たしかに、IssueではMisskey全体(ないし個別ページ)をSSRしたいように見えます その議論とは別にこのPRの一つ目の効用である開発体験向上に繋がり、 |
これについては HTTP API と密結合状態なのは解消できないと思っているので Storybook で実現した差がある(し一部しているつもり) |
(本当に必要なものって、環境変数で既存の公開サーバーを指定してViteがそこにプロキシする…というのはhttps絡みで難しいかしらね |
PRのオーナーが飽きたのでクローズします |
What
Misskeyの開発において、フロントエンドとバックエンドの単体での起動が可能になります。
これは pnpm dev で起動した場合のみで、 pnpm start の場合、今までと動作は変わらない想定です。
pnpm dev でバックエンドと疎通するには
.config/default.yml
で hostをhttps://localhost:3000/
にする必要がありますプロジェクトルートで pnpm dev をすると、フロントエンドとバックエンドのローカル開発環境が立ち上がります
http://127.0.0.1:5173/ ← viteのパス をブラウザで開いてください 注意:localhost:5173 ではいけません
また、バックエンドのポートである :3000 でもありません。
Note: フロントエンドとバックエンドを別々のシェルで起動したい
一つのシェルで frontendディレクトリに移動して pnpm dev、
もう一つのシェルでbackendディレクトリに移動してpnpm devでもよいです。
* プロジェクトルートのpnpm dev は、 すべてのworkspaceでpnpm devします
* backendには postgresqlとredisが起動している必要があります
Why
HMRが有効になり、開発体験が向上します。
(もはや、フロントエンドの変更を確認するのに都度ビルドする必要はありあません!)
BackendとFrontendを別々に起動/再起動した場合、 packages/backend, packages/frontend 配下でpnpm dev すればいつでもそれらのプロセスを個別にとめて再起動することができます
Additional info (optional)
PostgresqlとRedisを用意するのがめんどくさいのでこれらだけDockerでやりたい
postgresqlとredisだけ起動するdocker-compose.yml を同梱しました。
redisとpostgresqlだけ立ち上がります
テスト観点など
私の手元で何度か環境を作り直してうまく動いているように見えますが、少なからずビルドチェーンに手を加えているため多くの開発者によって検証するほうが良いでしょう。
Checklist