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

feat: handle plugins with Vite [LIBS-610] #863

Merged
merged 35 commits into from
Jul 25, 2024

Conversation

KaiVandivier
Copy link
Contributor

@KaiVandivier KaiVandivier commented Jul 11, 2024

LIBS-610

Accomplishes some nice things:

  1. Pretty much instant startup for plugins
  2. Removes webpack config and related CLI code
  3. Shared code & assets between app and plugin is great ✨ -- testing builds of the PWA example app with a plugin between master and this branch, the total build size is now less than half
  4. App and plugin are conceptually separated more in the CLI -- it's now easier to build a plugin without building an app
  5. Smaller cache size when developing a PWA app locally -- this was actually a problem with the webpack dev server too

Changes made:

  1. Vite config moved a file in shell to a function in the CLI to be more dynamic based on config. Requires Node API; used dynamic import and MJS
    1. Moved Vite deps to CLI from shell
    2. No longer need to execute ‘start’ and ‘build’ scripts in shell dir to make things happen
    3. Changed up Env handling a bit; need to do some more manual string replacement on things that were previously added to env via the CLI
  2. Added dynamic inputs to build process (don’t need it for the dev server; Vite just fires up everything in the root dir)
  3. Apps and plugins are now handled in the same process; don’t need two scripts
  4. Fixed up ‘deploy’ script for plugin without an app
  5. Changed up config validation & build process a bit to make it easier to handle plugins without apps
    1. Removed need for ‘getOriginalEntrypoints’ to tell if something actually has an app entrypoint defined or not
  6. Service worker
    1. Don’t need plugin precache manifest (it’s part of the rest)
    2. Added a special “Dev Network First” caching strategy to "hit two flies in one swing": avoid "cache bloat" from constantly updating source files with new version hashes, and enable going offline immediately after HMR updates (long story)
  7. Shell plugin files updated
    1. Refactored dynamic import — I forget exactly what was happening, but I think if an app was built without a plugin, the plugin HTML still tried to find that entry point but it wouldn't exist after the App replaced it
    2. Since app and plugin now run on the same script and have the same env vars, needed a new way to determine the ‘IS_PLUGIN’ var -- I chose to do a string replacement at bootstrapping time, which helps with dead code elimination (apps can drop all the plugin stuff). I used self.__IS_PLUGIN as the replacement target to distinguish it from other vars that are being populated from the env (kinda)

@KaiVandivier KaiVandivier requested a review from a team July 12, 2024 11:45
@KaiVandivier KaiVandivier merged commit ca5be0d into alpha Jul 25, 2024
5 checks passed
@KaiVandivier KaiVandivier deleted the libs-610-vite-for-plugins branch July 25, 2024 14:42
dhis2-bot added a commit that referenced this pull request Jul 25, 2024
# [12.0.0-alpha.5](v12.0.0-alpha.4...v12.0.0-alpha.5) (2024-07-25)

### Features

* handle plugins with Vite [LIBS-610] ([#863](#863)) ([ca5be0d](ca5be0d))
@dhis2-bot
Copy link
Contributor

🎉 This PR is included in version 12.0.0-alpha.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants