Skip to content

Build with Vite #1396

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

Open
wants to merge 59 commits into
base: dev
Choose a base branch
from
Open

Build with Vite #1396

wants to merge 59 commits into from

Conversation

binh-dam-ibigroup
Copy link
Collaborator

@binh-dam-ibigroup binh-dam-ibigroup commented May 15, 2025

Description

This PR sets Vite as the new build system.

We place customization files (CSS, JS, GraphQL) in the /tmp folder so that imports can use relative paths within the repo root. index.html is copied to the repo root for Vite to pick up, and gets some pre-processing (inject the main script and remove HTML comments).

Other things that we used to configure explicitly that are now included out-of-the-box:

  • lazy imports of YML files using variables (thanks to Vite's "glob import" feature)
  • hot reloading
  • minification
  • preview mode (used for Percy/a11y tests)
  • faster builds and simpler config than with Webpack
  • yarn start works out of the box, even with no environment variables passed (it will use the example subfolder).

Things that were dropped:

  • Old dependencies (some have been upgraded to play well with Vite)
  • Circular dependencies - There is a circular dependency plugin but I have not been able to make it work at this time, and it doesn't seem to be able to return a count of the circular dependencies found.
  • require syntax
  • trimet-mod-otp configs no longer work.

Things that don't change:

  • Babel and react-scripts are very much still here to run jest without making too many changes. Changes to jest should be handled separate from this PR.
  • mastarm deploy seems to still be working (all content in dist is flat, no subfolders)
  • No visual changes
  • No changes to custom configs (trimet-mod-otp configs no longer work).

PR Checklist:

  • Does the code follow accessibility standards (WCAG 2.1 AA Compliant)?
  • Are all languages supported (Internationalization/Localization)?
  • Are appropriate Typescript types implemented?

@@ -16,9 +14,5 @@
</head>
<body>
<div id="main"></div>
<script>
Copy link
Collaborator Author

@binh-dam-ibigroup binh-dam-ibigroup May 20, 2025

Choose a reason for hiding this comment

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

Vite will inject hot reloading code similar to this content in development mode (yarn start), so this is no longer needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the explanation!

// index.html is placed at the root of the repo for Vite to pick up.
customFile('HTML_FILE', './index.html', './lib/index.tpl.html')
customFile('CUSTOM_CSS', './tmp/custom-styles.css', './example/example.css')
customFile('YAML_CONFIG', './tmp/config.yml', './example/example-config.yml')
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Miles says hot reloading from the original customizations files is important.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think @daniel-heppner-ibigroup's suggestion of doing a symlink instead of a copy is a good idea!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@miles-grant-ibigroup and @daniel-heppner-ibigroup The old craco.config.js does copy the JS configs (and custom graphql) files. We can either: keep copying those files, so that no changes in the imports in those files are needed, or go ahead with symlinks, but that requires updating the imports of config.js that use OTP-RR relative paths. What do you think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@miles-grant-ibigroup and @daniel-heppner-ibigroup To avoid modifying custom files, I added a watch so it copies edited custom files over for hot reloading (e2d2774).

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice fix. Seems just as good as a symlink

Copy link
Contributor

Choose a reason for hiding this comment

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

It's so fast!

Copy link
Contributor

@daniel-heppner-ibigroup daniel-heppner-ibigroup 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 working really well. I am glad we resolved the config hot reloading issue so easily. I'm certainly impressed!

@@ -18,6 +17,7 @@ import {
ItineraryView
} from '../util/ui'
import { getModesForActiveAgencyFilter, getUiUrlParams } from '../util/state'
import { loadLocaleData } from '../util/i18n-loader'
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you remember what the purpose of moving this into its own file was? Just curious

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, it is to isolate the parts that use the Vite-specific glob imports. This file is mocked for tests (tests continue to use Babel).

@@ -16,9 +14,5 @@
</head>
<body>
<div id="main"></div>
<script>
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the explanation!

// index.html is placed at the root of the repo for Vite to pick up.
customFile('HTML_FILE', './index.html', './lib/index.tpl.html')
customFile('CUSTOM_CSS', './tmp/custom-styles.css', './example/example.css')
customFile('YAML_CONFIG', './tmp/config.yml', './example/example-config.yml')
Copy link
Contributor

Choose a reason for hiding this comment

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

It's so fast!

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.

4 participants