Shopify / hydrogen-v1

React-based framework for building dynamic, Shopify-powered custom storefronts.
https://shopify.github.io/hydrogen-v1/
MIT License
3.75k stars 326 forks source link

Consider removing vite.config.js #1088

Open jplhomer opened 2 years ago

jplhomer commented 2 years ago

Hydrogen is powered by Vite.

On the surface, it looks a lot like a standard Vite project, because we have a vite.config.js file with a simple hydrogen() plugin.

However, this is misleading:

To solve these problems, we should consider removing vite.config.js from the starter template, and adding a vite property to hydrogen.config.js, which was introduced in #1065.

This allows the developer to override certain Vite settings and apply plugins, but it's clear that the ability to customize Vite is merely an escape hatch allowed by Hydrogen and not a core expectation. This is similar to the behavior Next.js uses to customize Webpack.

To do this, we likely need to switch to a dedicated hydrogen dev and hydrogen build command rather than raw vite and vite build. There are additional benefits to this, too, like being able to provide better error messaging. I believe @cartogram is already working on this specific thing.

benjaminsehl commented 2 years ago

@frandiox — in the Plugin system you're exploring, we should follow through on this and remove the vite config file — though it would be nice to be able to eject this if necessary

frandiox commented 2 years ago

@benjaminsehl Yes, I've had this in mind for a while and some of the recent changes will make this possible. This will be implemented after the plugins.

One of the reasons I'm trying to introduce plugin/vite.js and so on is basically to remove vite.config.js. Plugins will be able to pass optimizeDeps and similar without the user doing anything. Eventually, we will be able to remove vite.config.js and allow users to create it to optionally add their own Vite config without doing anything Hydrogen-related in that file. In this case, it wouldn't even be considering "ejecting" since it's a completely optional file they add on their own.