Remix Vite: How to configure build target for client files vs server files? #8856
Replies: 3 comments 1 reply
-
Suggestion from remix discord
I would need to try this out sometime, but leaving this comment here in case someone else needed ideas too |
Beta Was this translation helpful? Give feedback.
-
The browser doesn't have CJS support, so the build always uses ESM, what else would you want to configure there? Meanwhile, Node can be used with CJS or ESM, so depending on your Node version and your HTTP server code you may need the server build to be CJS or ESM, that's why it's an option.
Build has always been split between client and server, before you had
It only configure the modules to use CJS ( Note that You can target ES2023 if you want and still use CJS in Node as the module format. |
Beta Was this translation helpful? Give feedback.
-
@cliffordfajardo Switching the module format might be harder, but switching the target version for server and client is possible. I am using this to get top-level await only on the server:
|
Beta Was this translation helpful? Give feedback.
-
Question
Is it possible to have a build target for the server bundle and another one for the client bundle?
Examples Use Cases:
Want to use modern JS for server & older style JS output for browser bundles to support older browsers
Keep top-await during the startup (server), and I don’t want to set target: esnext for the browser
There is a
serverModuleFormat
option for server build, but I'm having trouble finding options for client related bundle output:The
build
option you can pass to the top level object ofdefineConfig
is confusing and raises questions like:serverModuleFormat
inside ofremix
vite plugin but not something likebrowserModuleFormat
?build/{client, server}
would be nice to be able to target the build target directly for the finalserver
andclient
bundles inside the final build folderserverModuleFormat
overridebuild
or is it the other way around?Create fresh remix app command:
Related Discussions
vite build
error -- Transform failed with 3 errors - Top-level await is not available in the configured target environment #7969 (comment)Beta Was this translation helpful? Give feedback.
All reactions