Replies: 9 comments 21 replies
-
Do we need to pre-bundle/transform SSR dependencies in the first place? We are having many difficulties because Vite tries to transpile SSR code living in I believe a more sensible default would be to not transpile and not even touch SSR dependencies at all. As long as we correctly transpile user SSR code we should be good. As for ESM support, I believe we should respect the following rule:
This would solve the ESM compat problems we are having (e.g. Vuetify). |
Beta Was this translation helpful? Give feedback.
-
Re 1, if we do start applying plugins during pre-bundling, it would be similar to how snowpack's
Regardless of the concerns, this might be the only way to truly support raw vue/svelte/jsx. We will need to address these if we go down this path. Hoping @FredKSchott can give some insights for |
Beta Was this translation helpful? Give feedback.
-
Right now the plugins are Rollup plugins and the pre-bundling is done with esbuild, so how would this work exactly? |
Beta Was this translation helpful? Give feedback.
-
There are two big issues I see frequently hit:
|
Beta Was this translation helpful? Give feedback.
-
If nothing else, we should disable the optimizer in SSR middleware mode, since it's not even used, IIUC. |
Beta Was this translation helpful? Give feedback.
-
Are there any serious downsides to option 2 (bundling deps for production with esbuild)? I know it wouldn't solve the problem with deps that contain raw For context, my team's software has an on-premises version, and new releases are a pain. When I deployed my first Vite build, we caught some issues in our cloud deployment that hadn't manifested in development. We immediately rolled back, but things could have gone much worse if, for instance, the bugs hadn't been caught until after we cut a new onprem version. This is something that's really stressing me out as I work on getting our Vite build ready to re-merge, to the point where I'm seriously considering adding tooling that will require us to whitelist each individual CommonJS package in our frontend build. I'm curious how other developers using Vite in production right now are dealing with this -- there might well be less drastic mitigation steps that I'm missing. If there aren't, however, I'd really like to see a solution prioritized that gets dev and prod in line with each other, or even just identifies patterns in dependencies that trip common edge cases and warns or fails builds when a dependency exhibiting that pattern is imported. Of course, I'm happy to contribute in either regard if I can 🙂 |
Beta Was this translation helpful? Give feedback.
-
I have meet this problem while I use cjs export only module It exports At development(esbuild): import Icon from "@mdi/react"
Icon // function Icon () => { ... } At production(rollup, and cause react-dom errors): import Icon from "@mdi/react"
Icon // { default: function Icon() { ... } } After some debugging I come here, and what I did is simply: import { Icon } from "@mdi/react"
/* OR
import * as all from "@mdi/react"
const iconComponent = <all.Icon />
*/ In most cases, we don’t have time to wait for the library to release a new version that original supports esm. It doesn't matter for me to change the import manually. Sounds 2. pre-bundle dependencies for prod can give me a really good DX. This is my humble opinion, thank you. |
Beta Was this translation helpful? Give feedback.
-
Hey 👋 Is there any update on this? Especially point 1 would help us out a lot since it seems like it would fix what I described a while ago here: #7945 |
Beta Was this translation helpful? Give feedback.
-
Update somthing for No.2 (Use esbuild to also pre-bundle dependencies for prod). Vite 3.0.0 has supported an experimental feature: 3.0.0 2022-07-13 Release log: Experimental Features
BUT it's not enabled by default: official docs
|
Beta Was this translation helpful? Give feedback.
-
Some thoughts regarding dependencies / SSR / prod vs dev:
Apply plugins to non js/ts files found in dependencies during the pre-bundle phase.
Use esbuild to also pre-bundle dependencies for prod, then alias deps to the pre-bundled chunks during the Rollup build phase. This would
@rollup/plugin-commonjs
and reduce prod/dev inconsistency due to difference in handling CJS between esbuild &@rollup/plugin-commonjs
For SSR deps handling - probably want to (1) get rid of the external/non-external thing altogether (2) run a similar pre-bundle step using esbuild, apply ssr transforms on the resulting ESM, and cache them. Overall the goal is to make prod/dev/ssr-prod/ssr-dev all be as consistent as possible.
These are just general directions that I think may resolve some of the main issues I currently consider important - I don't have time to work on them properly just yet, but want to throw it out there for discussion, and maybe someone can experiment with these ideas.
Beta Was this translation helpful? Give feedback.
All reactions