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

[Debt] Migrate to vite #10611

Merged
merged 81 commits into from
Jun 21, 2024
Merged

[Debt] Migrate to vite #10611

merged 81 commits into from
Jun 21, 2024

Conversation

esizer
Copy link
Member

@esizer esizer commented Jun 6, 2024

πŸ€– Resolves #9840

πŸ‘‹ Introduction

Migrates from webpack to vite.

πŸ•΅οΈ Details

Watch vs Dev/Build

Thanks to @substrae we do not have to sacrifice the watch command. However it now works a little different. When running pnpm run dev/build everything works as you should expect. But in order to watch, we use vite's dev server for HMR. This means, when running watch, you should be using http://localhost:3000 (note the port number).

Now, when developing, you no longer need to refresh the browser! Vite will reload the browser and reload the components. It does this on demand so you may notice some flashing and temporary error pages but I think this is a good trade off.

Barrel exports

It may be time to revisit removing all barrel exports again since vite discourages it in their performance section. We do not do this too much but I think we still have some.

πŸ’” Breaking Changes

HTML Template

This has been moved to the root (expected by vite).

Environment variables

This has changed significantly. We no longer use the config.ejs file for runtime variables since vite supports ejs in the html template.

To add an environment variable, you still add it to the .env but instead of updated the config.ejs for runtime vars, you need to add it to:

  • vite.config.ts
  • vite-env.d.ts
  • index.html (for runtime only)

To access an environment variable, just reference it like a global constant. We no longer need to use the process.env anymore.

⭐ Bonus

Storybook

This seems to also resolve #10557 so it would benefit us for you to test that as well πŸ˜„

Codegen watch

I was also able to figure out why codegen watch was broken and fixed that here as well since it was only 2 character change πŸ˜…

πŸ§ͺ Testing

  1. Copy over new .env.example items (DEV_APP_URL, DEV_OAUTH_POST_LOGIN_REDIRECT, API_HOST)
  2. Clean out your modules make clean-modules
  3. Reinstall deps pnpm i
  4. Build pnpm run build
  5. Check to ensure app still works

@codecov-commenter
Copy link

codecov-commenter commented Jun 6, 2024

Codecov Report

Attention: Patch coverage is 20.98765% with 64 lines in your changes missing coverage. Please review.

Project coverage is 38.09%. Comparing base (5844ad8) to head (3e4059e).

Files Patch % Lines
api/app/Http/Controllers/AuthController.php 0.00% 9 Missing ⚠️
apps/web/src/pages/DirectivePage/Resources.tsx 50.00% 8 Missing ⚠️
apps/web/src/components/Footer/VersionLink.tsx 0.00% 6 Missing ⚠️
...ges/Home/IAPManagerHomePage/IAPManagerHomePage.tsx 0.00% 6 Missing ⚠️
...le/ExperienceFormPage/CreateExperienceFormPage.tsx 0.00% 6 Missing ⚠️
...file/ExperienceFormPage/EditExperienceFormPage.tsx 0.00% 6 Missing ⚠️
apps/web/src/components/Layout/IAPLayout.tsx 0.00% 4 Missing ⚠️
apps/web/src/components/Router.tsx 0.00% 4 Missing ⚠️
apps/web/src/main.tsx 0.00% 3 Missing ⚠️
...estionnaire/sections/GeneralInformationSection.tsx 0.00% 3 Missing ⚠️
... and 7 more
Additional details and impacted files
@@             Coverage Diff              @@
##               main   #10611      +/-   ##
============================================
- Coverage     38.17%   38.09%   -0.08%     
- Complexity     1645     1646       +1     
============================================
  Files          1019     1021       +2     
  Lines         31339    31338       -1     
  Branches       6623     6646      +23     
============================================
- Hits          11963    11938      -25     
+ Misses        19351    19223     -128     
- Partials         25      177     +152     
Flag Coverage Ξ”
integrationtests 68.18% <0.00%> (-0.10%) ⬇️
unittests 30.92% <23.61%> (-0.09%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

β˜” View full report in Codecov by Sentry.
πŸ“’ Have feedback on the report? Share it here.

@vd1992
Copy link
Contributor

vd1992 commented Jun 18, 2024

Okay, I think things look better now, let us get some other eyes on this πŸ‘€

@mnigh mnigh self-requested a review June 18, 2024 20:31
Copy link
Contributor

@mnigh mnigh left a comment

Choose a reason for hiding this comment

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

πŸ₯³ this is so great!

❓ perhaps it is worth enabling the Chromatic workflow and running it on this PR as well, if the intent is for this PR to resolve that issue?

Important

my approval is limited to local testing (similar to @vd1992's implicit approval). i would wait to merge until @petertgiles is confident with deploying and testing on remote servers.

@esizer esizer requested a review from petertgiles June 20, 2024 18:10
@petertgiles
Copy link
Contributor

Build error in router.tsx 😒

@esizer
Copy link
Member Author

esizer commented Jun 20, 2024

Build error in router.tsx 😒

Not really sure why this occurred πŸ˜• . But it is now fixed with split experience form pages into own files

@vd1992

This comment was marked as resolved.

@esizer
Copy link
Member Author

esizer commented Jun 21, 2024

What exactly is the difference between run dev and run build ? Can't quite tell the difference despite it correctly outputting "building for production/development"

It is subtle but important, dev command changed the NODE_ENV which will allow us to modify env vars if we want. In addition to that, it will create source maps for better debugging. These source maps are external so you shouldn't really notice them in the actual bundle size.

Dev mode strips all this out to create a more optimized build for production.

As for watch, the request number is so high becuase of how the HMR works. It dynamically loads chunks of code into the browser on demand and does this often (on every file save) to update the page.

@vd1992
Copy link
Contributor

vd1992 commented Jun 21, 2024

Thanks for answering

I noticed that there is a pnpm run build-storybook that outputs to /gc-digital-talent/apps/web/storybook-static
How do I use it or reach it lol

Playing around with the various scripts, think we had a bug in one of them
The web one should point at /web right?

image

pnpm run lint keeps crashing for me, anyone else having issues with it? Same with running jest. Process killed or WSL crash
EDIT: Lint and test run fine if executed in /apps/web 🀷

Playwright still works well, as does codegen and tsc

@esizer
Copy link
Member Author

esizer commented Jun 21, 2024

I noticed that there is a pnpm run build-storybook that outputs to /gc-digital-talent/apps/web/storybook-static
How do I use it or reach it lol

It is set in the chromatic workflow. The folder name is the standard name so it just gets picked up there.

Playing around with the various scripts, think we had a bug in one of them
The web one should point at /web right?

It is a little confusing but, it is pointing to the correct location. The script is chekcing web but it is run in that package since it uses the cli.ts file in that package.

"check-intl": "tsx ./src/cli.ts",

Copy link
Contributor

@petertgiles petertgiles left a comment

Choose a reason for hiding this comment

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

This is amazing. 😍 Locally, lint, Playwright, watch, storybook all work great.

I'm tracking only two "only in Azure" issues here.

.github/workflows/chromatic.yml Show resolved Hide resolved
.github/workflows/chromatic.yml Show resolved Hide resolved
@esizer esizer added this pull request to the merge queue Jun 21, 2024
Merged via the queue into main with commit 66aa82f Jun 21, 2024
11 of 14 checks passed
@esizer esizer deleted the 9840-migrate-vite branch June 21, 2024 20:47
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.

πŸ› Storybook not building ♻️ Migrate to vite
6 participants