-
Notifications
You must be signed in to change notification settings - Fork 0
web-server で使っている Next.js を Vite に置き換える #613
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…eact/quick-start#manual-setup に従い、TanStack Routerのサンプルを作成
Floconの各パッケージがライセンス一覧に含まれないように `private: true` を付けた
- いくつかのボタンは実行中のときに自動的にdisabledになるようにした - loggerRefに、型がunknownであるオブジェクトを渡せるメソッドを追加 - ログの一部の文字が `[object Object]` などになってしまう問題を修正 - その他バグを修正
web-serverに@flocon-trpg/eslint-configを適用 lintの警告をいくつか修正
3b87cc9 to
1671c41
Compare
1671c41 to
516bc06
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
今まで web サーバーのフレームワークとして Next.js を使っていたが、Vite に置き換えることにした。Remix 等ほかの選択肢も検討したが、Vite を使うことに決定した。
Next.js を使っていた理由
Flocon の web サーバーには今まで Next.js を使ってきた。Next.js を導入した理由は次のとおり。
next exportで静的ファイルのエクスポートができる。比較的楽に Flocon の web サーバーを立てたい方に便利だと思われる機能である。その一方で、Next.js の豊富な機能のほとんどは Flocon には必要ないという状況であった。Flocon が Next.js に求めていた部分はむしろ逆で、 最低限の設定で利用可能なシンプルなビルドツールであった。
Next.js をやめる理由
ここ最近は、Next.js のバージョンアップに付いていく学習コストが高そうで大変だと感じてきた。コードの変更も必要。しかもそのバージョンアップで追加される機能は Flocon には必要のないものがほとんど。そのため Next.js から他のフレームワークに乗り換えることに決めた。
乗り換え先候補
これらは Flocon の web-server に必要な機能を備えていると思われる。
https://qiita.com/takumi3488/items/bc14b537f49704a1cf16 も読んだほうがよさそう?
Vite と Remix の比較
Vite はフロントエンドビルドツールであり、Remix は full stack web framework。ただし単に静的ファイルを出力したいという目的であればどちらも適していると思われる。
Remix は Vite のプラグインという立ち位置。
Remix 公式曰く「we now support Vite as an alternative compiler. In the future, Vite will become the default compiler for Remix.」 - https://remix.run/docs/en/main/guides/vite
実際に両方使ってみての感想
Flocon の web サーバーのコードを最初 Vite に移行し、その次に Remix に移行した。そこで実際に触ってみての感想。
Remix では file-based routing は標準サポートだが、Vite ではプラグインが必要。そのため Vite では
@tanstack/react-routerをプラグインとして使ってみたが、コンポーネントを export する際にコードを追加で3行ほど書く必要がある以外は特に不満点はなかった。Remix だと JavaScript ファイルが自動分割されるので便利。ただし Flocon ではあまり重要でないかも。
Remix では meta を route ごとに設定する機能が自動でついている。ただし Flocon では使わなくても大丈夫そう。
Vite はあまりエラーが出なかったが、Remix ではいくつかエラーが出たので修正する必要があった。このことを考えると、将来新たなエラーに遭遇する確率も Remix のほうが高そう。
[remix] Named export 'useAsync' not found. The requested module 'react-use' is a CommonJS module, which may not support all module.exports as named exports.というエラーが出た。他に lodash でも確認した(lodashは古いのでせっかくなのでes-toolkitに置き換えた)。vite.config.ts内のssr.noExternalに react-use を含めることで解決できた。https://github.com/remix-run/remix/discussions/8934に同様の issue がある。vite.config.tsの remix プラグインを無効にする必要があった。<Board />を利用する際にReact.lazyを使って読み込まないと konva のエラーが出た。ただしこれは Next.js でも同様であり、そのときは next/dynamic で対処していた。結論としては、現時点では Flocon の web サーバーには Vite を使うことにした。Vite を使うのであれば代わりに Farm を使ったほうがいいという意見もあるが、Vite のほうが利用者が多くサポートの継続性が高そうなのと、Farm は v1.0 がリリースされたのが 2024/4/15 なので少し新しすぎるため少し様子見したいと考えて Vite にした。
Flocon に生じる breaking changes(未確定、未調査のものも含む)
将来breaking changesになる可能性
NEXT_PUBLIC_になっているが、将来これをやめてVITE_かFLOCON_等になるかも