-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Supports ES SSR build based on module
type
#2157
Conversation
5cd7c14
to
3553a8a
Compare
+1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you rebase this against the main
branch? There's been some shuffling around of some code and this section is now in the buildOuputOptions
function.
vite/packages/vite/src/node/build.ts
Lines 399 to 403 in 1eb648e
const buildOuputOptions = (output: OutputOptions = {}): OutputOptions => { | |
return { | |
dir: outDir, | |
format: ssr ? 'cjs' : 'es', | |
exports: ssr ? 'named' : 'auto', |
Yes, with the typo of "Output" -> "Ouput", oops. Would be great if you can also fix the typo. 😬
3553a8a
to
2af6cea
Compare
No worries! Rebased and corrected that typo |
@rschristian ssr externals are imported using require at this point:
Could you check if this needs reworking as part of this PR? |
I'll take a peek, yeah. Worked when I opened this PR, but that was a couple months ago now. |
@patak-js Took me a bit to finagle the CJS SSR example into shape, but ESM server output is generated and everything seems to be correct / as I'd expect it with this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We discussed this PR with Evan:
- This change needs a playground test that uses
"type": "module"
, we could change one of the ssr playgrounds to match. - This needs to be configurable, as there are situations in which you may want to build an ESM project to a CJS output (e.g. serverless functions currently require a CJS entrypoint).
This will override the SSR output. When the configuration option is not present, we can fall back to this PR's default of assuming
ssr.format?: 'cjs' | 'es'
"type": "module"
= ESM. - We'll need to expose an SSR flag for the Vite config like so:
Where
export default ({ command, mode, ssr }) => {
ssr
is a boolean that is true in SSR mode. This also needs a test.
Will try to get that done next block of time I can find. |
@GrygrFlzr Are you looking for a
Also not super sure how this relates to this PR in anyway? Seems like something that should be separate? |
I added a new playground that uses That being said, I couldn't figure out your test suite at all. Frankly I have no clue what's going on it in, way too much magic for my Sunday night brain. Essentially just need to make sure that Regardless, I'm on vacation for the next 2-ish weeks and won't be touching this for the duration. I'm not a user of Vite anyhow, and have 0 familiarity with the code base, so feel free to take this PR over and push to it or what not. You'll know better what you're looking for here. |
9ad8bfe
to
4d21b7a
Compare
Summary
Closes #2152
When
"type": "module"
is set for a package,vite build --ssr
will not build to CJS, but ESMI'm not sure if it's worth adding a test for this? It would basically just be a test checking the the ability to read the package file and Rollup's ability to output ES. Let me know if I should though, I certainly can.