Skip to content
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

feat: default esm SSR build, simplified externalization #501

Merged
merged 2 commits into from Jun 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions config/ssr-options.md
Expand Up @@ -24,3 +24,11 @@ SSR の依存関係を強制的に外部化します。
- **デフォルト:** `node`

SSR サーバのビルドターゲット。

## ssr.format

- **型:** `'esm' | 'cjs'`
- **デフォルト:** `esm`
- **実験的機能**

SSR サーバのビルドフォーマット。Vite 3 以降の SSR ビルドはデフォルトで ESM を生成します。`'cjs'` を選択すると CJS が生成されますが、おすすめではありません。このオプションは、ユーザーが ESM にアップデートするまでの時間を設けるために、実験的機能のままにしています。CJS ビルドには、ESM フォーマットにはない複雑な外部化ヒューリスティックが必要です。
7 changes: 7 additions & 0 deletions vite.config.ts
@@ -0,0 +1,7 @@
import { defineConfig } from 'vite'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

viteのバージョンが本家と異なるためなのかは分かりませんが、defineConfig内のオプション項目にssrがなくエラー表示されています。

↓このあたりについて本家でやりとりされている箇所
vitejs/vite#8348 (comment)

反映する必要があるのか判断に迷ったのですが、
本家の/docsは翻訳リポジトリのルートディレクトリなので対応範囲内なので、対応しました。

一応、yarn docs実行してのビルドエラーはなく、ページ表示も問題ないことは確認しました。


export default defineConfig({
ssr: {
format: 'cjs'
}
})