Skip to content
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: Add plugin option for custom outDir #591

Merged
merged 14 commits into from
Aug 3, 2024

Conversation

waigel
Copy link
Contributor

@waigel waigel commented Jul 31, 2024

Corrected the build process to honor the user-defined outDir setting in the Vite configuration.

@waigel waigel marked this pull request as draft July 31, 2024 01:44
Copy link
Owner

@hi-ogawa hi-ogawa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, thanks for taking a look. It wasn't a priority but obviously hard-coding dist/ everywhere is not great and I was hoping I can clean this up someday.

If you have a concrete motivation to change outDir other than dist, then I would like to know the reason as it helps setting the priority.

packages/react-server/src/entry/ssr.tsx Outdated Show resolved Hide resolved
@hi-ogawa
Copy link
Owner

On second thought, I think trying to reuse Vite config's outDir as user option might be conceptually difficult. What Sveltekit does is to expose outDir option (default .svelte-kit) as svelte.config.js opiton https://kit.svelte.dev/docs/configuration#outdir.

Probably it makes sense to not support outDir as vite config level, but only support it as plugin option i.e.

// vite.config.ts
export default defineConfig({
  plugins: [
    vitePluginReactServer({
      outDir: "custom-dir", // here okay
    })
  ],
  build: {
    outDir: "...", // not supported here
  }
})

This probably sets the expectation better and also code becomes less confusing?

@waigel
Copy link
Contributor Author

waigel commented Jul 31, 2024

Hey, thank you so much for your detailed feedback and for taking the time to provide tips for improvement. I really appreciate your insights!

Firstly, the reason for customizing the outDir is primarily due to internal considerations related to existing workflows and build caches. While this is not a high-priority issue, I agree that it should be more configurable, as you have mentioned.

I would be happy to assist with this feature and will carefully review your comments to revise the draft accordingly.

Additionally, I believe you are right that a custom plugin-scoped outDir makes more sense and would be clearer to communicate. I will continue the approach.

Copy link
Owner

@hi-ogawa hi-ogawa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the follow up! It looks about right, but I think there are a few missing on react-server-next adapter side

export async function build({ runtime }: { runtime: VercelRuntime }) {
const buildDir = join(process.cwd(), "dist");

You can also add your example on CI. I wasn't sure if adding an entire example is worth it but for now it should be fine. You can add it to test-react-server-others job around here:

test-react-server-others:
runs-on: ubuntu-latest
steps:

I just approved CI run on this PR, so you can check it.

packages/react-server/src/plugin/index.ts Outdated Show resolved Hide resolved
packages/react-server/src/entry/ssr.tsx Outdated Show resolved Hide resolved
@waigel waigel changed the title fix: Ensure Vite respects custom outDir in build configuration feat: Add plugin option for custom outDir Aug 2, 2024
@waigel waigel marked this pull request as ready for review August 2, 2024 19:00
@waigel
Copy link
Contributor Author

waigel commented Aug 2, 2024

I’ve addressed your feedback and implemented the changes. I’m confident I’ve covered all the hard-coded ‘dist’ directories, and the pipeline should now pass smoothly, even with the new e2e tests.

@hi-ogawa
Copy link
Owner

hi-ogawa commented Aug 3, 2024

Awesome, code looks good to me! I might tweak tests for my own taste, but we should be able to merge this soon. Thanks a lot.

If you want to test this out early, you can grab packages built from this PR here https://github.com/hi-ogawa/vite-plugins/runs/28288606525

You can use it like "@hiogawa/react-server": "https://pkg.pr.new/hi-ogawa/vite-plugins/@hiogawa/react-server@af4f6b6" in your package dependencies.

@@ -0,0 +1,12 @@
import type React from "react";

export default function Layout(props: React.PropsWithChildren) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have default root layout (I think next.js has it?), so we need to add one here. Otherwise, ssr/hydration is failing since they expect <html> and <body> are rendered.

packages/react-server/src/entry/ssr.tsx Show resolved Hide resolved
@hi-ogawa
Copy link
Owner

hi-ogawa commented Aug 3, 2024

Merging. Thanks for the contribution!

@hi-ogawa hi-ogawa merged commit 614b597 into hi-ogawa:main Aug 3, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants