johannschopplich / kirbyup

🆙 Official bundler for Kirby Panel plugins
https://kirbyup.getkirby.com
MIT License
51 stars 3 forks source link

fix: externalize Vue in serve mode, too #41

Closed jonaskuske closed 1 year ago

jonaskuske commented 1 year ago

Kirby 3.9.5 makes Vue accessible globally via window.Vue, so the Kirby Panel and plugins built with kirbyup can now share and access the same copy of vue. This is a requirement for Vue 2.7 functionality like dynamic CSS variables and <script setup> (https://github.com/getkirby/kirby/issues/4735), for usage of Vue Dev Tools (https://github.com/getkirby/kirby/issues/4796) and also allows usage of dependencies that import { X } from 'vue' within plugins built with kirbyup (https://github.com/johannschopplich/kirbyup/issues/24).

The externals and globals options in Rollup only work for UMD and IIFE output formats and are only applied during build, so in HMR mode (kirbyup serve), Vue is not externalized and plugins still try to import their own copy. (which is causing issues) To fix this, we can use rollup-plugin-external-globals, the same plugin Kirby is using, to externalize Vue consistently – in serve mode, too.

johannschopplich commented 1 year ago

Great stuff, Jonas! 👏