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

Allow customising the Vite config #1465

Merged
merged 8 commits into from
Oct 9, 2023
Merged

Allow customising the Vite config #1465

merged 8 commits into from
Oct 9, 2023

Conversation

infomiho
Copy link
Contributor

@infomiho infomiho commented Oct 3, 2023

It allows the user to specify the overrides for the Vite config which is used for the React web app. Closes #1085

How it works

Users need to define a vite.config.ts or a vite.config.js in their src/client folder. Wasp picks up this file and uses the contents of it to override the defaults.

For example, one such override would be "Does the browser open by default when a Wasp project is started?":

export default {
  server: {
    open: false,
  },
};

Demo app

There is a simple demo app in waspc/examples/vite-config-demo for testing purposes.


// https://vitejs.dev/config/
export default defineConfig({
{=# isCustomViteConfigUsed =}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the file is defined, we import it. If not, we use an empty object.

};

// https://vitejs.dev/config/
export default mergeConfig(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using the built-in Vite helper to merge the objects.

@@ -0,0 +1,6 @@
export default {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Example overrides.

waspc/data/Generator/templates/react-app/vite.config.ts Outdated Show resolved Hide resolved
waspc/src/Wasp/AppSpec.hs Outdated Show resolved Hide resolved
waspc/src/Wasp/Generator/WebAppGenerator/Vite.hs Outdated Show resolved Hide resolved
Signed-off-by: Mihovil Ilakovac <[email protected]>
@@ -76,7 +77,7 @@ data AppSpec = AppSpec
-- | Connection URL for a database used during development. If provided, generated app will
-- make sure to use it when run in development mode.
devDatabaseUrl :: Maybe String,
isCustomViteConfigUsed :: Bool
customViteConfigPath :: Maybe (Path' (Rel SourceExternalCodeDir) File')
Copy link
Member

Choose a reason for hiding this comment

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

You made it relative to SourceExternalCodeDir -> that is correct, I am just wondering, do we care if it is in external code dir or not? Because we could be less specific and say it is in source project dir (so root of source project). Then it could be in ext src, or not, who knows. But ok, this is also fine on one hand, especially if you are relying on this property of it being in ext src.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Either we add the src part in the AppSpec creation part or we add it in the generator 🤷 I think it's a bit arbitrary and maybe just keep it like this for now? I don't really any good reasons

Copy link
Member

@Martinsos Martinsos Oct 6, 2023

Choose a reason for hiding this comment

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

It's more about constraints -> is it important for us that custom vite config is in source external code dir? In the sense that, if I was doing some new code changes and moved it out of external code dir somewhere else, you would complain when reviewing it? If so, then let's leave it as it is. If it doesn't matter, and we are ok with it being anywhere in the project, but for now we chose source external code dir, then I would go with the path starting from the root of the project.

waspc/src/Wasp/Project/Vite.hs Show resolved Hide resolved
waspc/src/Wasp/Project/Vite.hs Outdated Show resolved Hide resolved
Copy link
Member

@Martinsos Martinsos left a comment

Choose a reason for hiding this comment

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

LGTM, approved! One comment is only left, the one with which StrongPath to use for the custom vite config, but I am ok with both options, so give it a read, do as you like, and feel free to merge.

Copy link
Member

@Martinsos Martinsos left a comment

Choose a reason for hiding this comment

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

@infomiho LGTM, but the main thing missing I think is to add a caution message that they can mess up things by doing this, so let's add that and we can merge!


export default defineConfig({
server: {
open: true,
Copy link
Member

Choose a reason for hiding this comment

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

Ok, nice!

})
```
</TabItem>
</Tabs>
Copy link
Member

Choose a reason for hiding this comment

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

You should mention that they might break stuff if they over-customize it, because we expect some stuff in vite config to be configured in a specific way, so they should be careful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense, I'll add that part as well 👍

@infomiho infomiho merged commit 88d9534 into main Oct 9, 2023
4 checks passed
@infomiho infomiho deleted the miho-custom-vite branch October 9, 2023 13:40
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.

Allow extending the Vite config
2 participants