dhis2 / app-platform

DHIS 2 application platform layer with inverted app control
https://platform.dhis2.nu
BSD 3-Clause "New" or "Revised" License
27 stars 16 forks source link

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

Closed KaiVandivier closed 3 months ago

KaiVandivier commented 4 months ago

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)
dhis2-bot commented 3 months ago

:tada: This PR is included in version 12.0.0-alpha.5 :tada:

The release is available on:

Your semantic-release bot :package::rocket: