.server
模組雖然不是絕對必要,但 .server
模組是明確標記整個模組為僅限伺服器端的好方法。如果 .server
檔案或 .server
目錄中的任何程式碼意外地出現在用戶端模組圖中,則建置將會失敗。
app
├── .server 👈 marks all files in this directory as server-only
│ ├── auth.ts
│ └── db.ts
├── cms.server.ts 👈 marks this file as server-only
├── root.tsx
└── routes
└── _index.tsx
.server
模組必須位於您的 Remix 應用程式目錄中。
有關更多資訊,請參閱側邊欄中的「路由模組」部分。
.server
目錄。經典 Remix 編譯器僅支援 .server
檔案。
.server
模組會被替換為空模組,並且不會導致編譯錯誤。請注意,這可能會導致執行階段錯誤。