Daydreamer-riri / vite-react-ssg

Static-site generation for React on Vite.
https://vite-react-ssg.netlify.app/
MIT License
125 stars 6 forks source link

[Proposal] Do not replace my build command #7

Closed condorheroblog closed 11 months ago

condorheroblog commented 11 months ago

I hope vite-react-ssg is just a plugin for Vite. It should not replace my build command, neither in theory nor in practice:

I wish to keep my original build command:

"scripts": {
    "dev": "vite",
    "build": "tsc && vite build",
    "preview": "vite preview"
}

Instead of being replaced by the following

"scripts": {
    "dev": "vite-react-ssg dev",
    "build": "tsc && vite-react-ssg build",
    "preview": "vite preview"
}

This replacement will lose the function of Vite itself

  1. Parameters supported by Vite cli are no longer valid, such as vite --port 3000
  2. When the user specifies base, such as /vite-plugin-fake-server/ and opens http://localhost:9000/ in the browser, it will automatically redirect to http://localhost:9000/vite -plugin-fake-server/
  3. Others

If vite-react-ssg can be run as a plugin, I also recommend having a parameter like enable to set whether to enable the plugin.

import { viteReactSSG } from 'vite-react-ssg';

export default defineConfig({
  plugins: [
    viteReactSSG({ enable: true }),
  ],
});

vite-ssg implements not modifying the user's dev command, but it doesn't implement not replacing the build command. So I'm not sure if vite-react-ssg can be used as a plugin.

I have some preliminary thoughts and suggestions that I hope could contribute to improving your plugin.

I genuinely appreciate your plugin🙏.

Daydreamer-riri commented 11 months ago

I can't think of a way to implement SSG as a Vite plugin. The SSR examples provided by the Vite official are also outside of the Vite ecosystem, using Vite API to implement SSR.

Regarding vite-ssg, the reason it doesn't replace the dev command is because it uses CSR (which is Vite's default behavior) during development. Vite-ssg doesn't do anything during development. Personally, I hope to provide SSR (Server-Side Rendering) during development to ensure consistency between development and production as much as possible.

You can see: https://github.com/Daydreamer-riri/vite-react-ssg?tab=readme-ov-file#use-csr-in-development-environment

Regarding your suggestion, in the situation where we cannot implement vite-react-ssg as a Vite plugin (as I believe), we can strive to enhance the CLI functionality of vite-react-ssg.