.server
模块¥.server
modules
虽然并非绝对必要,但 .server
模块是将整个模块明确标记为仅服务端的好方法。如果 .server
文件或 .server
目录中的任何代码意外地出现在客户端模块图中,构建将失败。
¥While not strictly necessary, .server
modules are a good way to explicitly mark entire modules as server-only.
The build will fail if any code in a .server
file or .server
directory accidentally ends up in the client module graph.
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
modules must be within your Remix app directory.
有关更多信息,请参阅侧边栏中的路由模块部分。
¥Refer to the Route Module section in the sidebar for more information.
.server
目录仅在使用 Remix Vite 时受支持。Classic Remix 编译器 仅支持 .server
文件。
.server
模块将被替换为空模块,不会导致编译错误。请注意,这可能会导致运行时错误。