Skip to content

Commit

Permalink
Add ssr.noExternal to the SPA template vite config
Browse files Browse the repository at this point in the history
  • Loading branch information
brophdawg11 committed Feb 28, 2024
1 parent 99b3e55 commit 780c462
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion docs/future/spa-mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ startTransition(() => {
- It's important to note that Remix SPA mode generates your `index.html` file by performing a "pre-render" of your root route on the server during the build
- This means that while you're creating a SPA, you still have a "server build" and "server render" step, so you do need to be careful about using dependencies that reference client-only aspects such as `document`, `window`, `localStorage`, etc.
- Generally speaking, the way to resolve these issues is to import any browser-only libraries from `entry.client.tsx` so they don't end up in the server build
- Otherwise, you can generally solve these by using [`React.lazy`][react-lazy] or the [`<ClientOnly>`][client-only] component from `remix-utils`.
- Otherwise, you can generally solve these by using [`React.lazy`][react-lazy] or the [`<ClientOnly>`][client-only] component from `remix-utils`
- The [SPA Mode template][spa-mode-template] also includes the Vite [ssr.noExternal][vite-ssr-noexternal] config by default to automatically bundle all of your dependencies during the server build to avoid most ESM/CJS issues

## Migrating from React Router

Expand Down Expand Up @@ -269,3 +270,5 @@ Once you've got all your routes living in their own files, you can:
[client-only]: https://github.com/sergiodxa/remix-utils?tab=readme-ov-file#clientonly
[vite-preview]: https://vitejs.dev/guide/cli#vite-preview
[sirv-cli]: https://www.npmjs.com/package/sirv-cli
[spa-mode-template]: https://github.com/remix-run/remix/tree/main/templates/spa
[vite-ssr-noexternal]: https://vitejs.dev/config/ssr-options#ssr-noexternal
5 changes: 5 additions & 0 deletions templates/spa/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@ import tsconfigPaths from "vite-tsconfig-paths";

export default defineConfig({
plugins: [remix({ ssr: false }), tsconfigPaths()],
ssr: {
// Bundle all dependencies during the server build by default to avoid
// most ESM/CJS issues
noExternal: true,
},
});

0 comments on commit 780c462

Please sign in to comment.