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

Config: Migrate from CRA to Vite (wait for release 1.9.0 to merge) #688

Merged
merged 36 commits into from
Mar 13, 2024

Conversation

drikusroor
Copy link
Contributor

@drikusroor drikusroor commented Dec 23, 2023

I would hereby like to propose to think about migrating from CRA (Create React App) to Vite. CRA - which runs on Webpack under the hood - is a facebook/create-react-app#13072 and the React team no longer recommends it (CRA used to be on that page). They do recommend things like Next.js or Remix, which we could also consider, but those projects require a completely different setup (with server-side rendering). For our situation - serving a build of static assets - Vite is probably the best option. I have used Vite in React projects before and I have also migrated CRA projects to Vite before. Apart from the fact that CRA is no longer maintained, Vite also has benefits:

It's way faster (hence the name, Vite is fast in French)
It has typescript built-in, making it easier to migrate to typescript if we want to
For the rest not much changes. The application works more or less the same. There are some files and folders that need to be in a different location and the environment variables are no longer to be prefixed with REACT_APP_, but with VITE_.

@drikusroor drikusroor self-assigned this Dec 26, 2023
@drikusroor drikusroor added enhancement New feature or request dependencies Pull requests that update a dependency file labels Dec 26, 2023
@drikusroor drikusroor force-pushed the config/migrate-to-vite branch 2 times, most recently from c02fa13 to 44a5e34 Compare January 8, 2024 14:59
@drikusroor drikusroor force-pushed the config/migrate-to-vite branch from 44a5e34 to ae1d899 Compare January 9, 2024 13:46
@BeritJanssen
Copy link
Collaborator

Why?

@drikusroor
Copy link
Contributor Author

Why?

A very good question! Apparently I have forgotten to provide a proper explanation in the PR description 😅 So yes, I would hereby like to propose to think about migrating from CRA (Create React App) to Vite. CRA - which runs on Webpack under the hood - is a deprecated / dead / no longer maintained project and the React team no longer recommends it (CRA used to be on that page). They do recommend things like Next.js or Remix, which we could also consider, but those projects require a completely different setup (with server-side rendering). For our situation - serving a build of static assets - Vite is probably the best option. I have used Vite in React projects before and I have also migrated CRA projects to Vite before. Apart from the fact that CRA is no longer maintained, Vite also has benefits:

  • It's way faster (hence the name, Vite is fast in French)
  • It has typescript built-in, making it easier to migrate to typescript if we want to

For the rest not much changes. The application works more or less the same. There are some files and folders that need to be in a different location and the environment variables are no longer to be prefixed with REACT_APP_, but with VITE_.

@drikusroor drikusroor force-pushed the config/migrate-to-vite branch from ae1d899 to 2311348 Compare January 24, 2024 13:07
@drikusroor drikusroor marked this pull request as ready for review January 24, 2024 13:32
.env-github-actions Outdated Show resolved Hide resolved
Copy link
Collaborator

@BeritJanssen BeritJanssen left a comment

Choose a reason for hiding this comment

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

Nice! Still have to see how it plays out in practice. Please do change the VITE_... variable names to something more descriptive, see my comments. Users need to at least have an idea of what these variables are for.

@drikusroor drikusroor force-pushed the config/migrate-to-vite branch 2 times, most recently from 447ba19 to 285f2bd Compare January 29, 2024 14:57
@drikusroor drikusroor force-pushed the config/migrate-to-vite branch from 285f2bd to e48ee6e Compare January 30, 2024 09:04
@drikusroor drikusroor changed the title Config: Migrate from CRA to Vite Config: Migrate from CRA to Vite (wait for release 1.9.0 to merge) Feb 27, 2024
Copy link
Collaborator

@BeritJanssen BeritJanssen left a comment

Choose a reason for hiding this comment

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

Can you please still change the variable names here? Either leave it as REACT (since we're still serving / building React here), or change to FRONTEND. The last setting in this list (STRICT) is arguably a React setting, right?

@drikusroor
Copy link
Contributor Author

Can you please still change the variable names here? Either leave it as REACT (since we're still serving / building React here), or change to FRONTEND. The last setting in this list (STRICT) is arguably a React setting, right?

That's not possible. CRA requires REACT_APP as prefix, but Vite requires VITE_ as prefix for environment variables.

@BeritJanssen
Copy link
Collaborator

BeritJanssen commented Mar 4, 2024

All the variable names were chosen and set by ourselves. So if it says "process.env.REACT_APP..." in the code somewhere, that comes from this environment variable. This doesn't have anything to do with CRA, as far as I'm aware.
My bad: turns out that indeed CRA auto-ignores all environment variables not prefixed with REACT_APP, and then Vite must have similar behaviour, but for VITE. Would our internal variables perhaps still deserve a more descriptive name? So that we have in the docker-compose: VITE_SOMETHING=${FRONTEND_SOMETHING}? Or do you think this might be even more confusing?

@drikusroor
Copy link
Contributor Author

All the variable names were chosen and set by ourselves. So if it says "process.env.REACT_APP..." in the code somewhere, that comes from this environment variable. This doesn't have anything to do with CRA, as far as I'm aware. My bad: turns out that indeed CRA auto-ignores all environment variables not prefixed with REACT_APP, and then Vite must have similar behaviour, but for VITE. Would our internal variables perhaps still deserve a more descriptive name? So that we have in the docker-compose: VITE_SOMETHING=${FRONTEND_SOMETHING}? Or do you think this might be even more confusing?

Yeah, we can definitely do that, especially since we have to update our environment variables anyway 👍

@drikusroor drikusroor force-pushed the config/migrate-to-vite branch from dc1a4b0 to fe7e2c1 Compare March 5, 2024 16:48
@drikusroor drikusroor requested a review from BeritJanssen March 6, 2024 17:16
@drikusroor drikusroor force-pushed the config/migrate-to-vite branch from e0c7fc4 to 84ee818 Compare March 13, 2024 12:48
@drikusroor drikusroor merged commit 2c303a0 into develop Mar 13, 2024
10 checks passed
@drikusroor drikusroor deleted the config/migrate-to-vite branch March 13, 2024 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file enhancement New feature or request on hold
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants